// 蜂窝蜜造平台生成代码，如手工更改，请添加到 .beeignore 忽略生成

package com.fowo.api.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fowo.api.common.annotaion.DataObjectType;
import com.fowo.api.common.config.CacheConfig;
import com.fowo.api.common.excel.CustomExcelExport;
import com.fowo.api.common.excel.CustomExcelHandler;
import com.fowo.api.common.excel.ExcelConfig;
import com.fowo.api.common.excel.TemplateModelBuildEventListener;
import com.fowo.api.common.model.ImportRow;
import com.fowo.api.common.model.JoinModel;
import com.fowo.api.common.model.OptionItem;
import com.fowo.api.common.model.PageSearch;
import com.fowo.api.common.model.RException;
import com.fowo.api.common.util.ContextHolder;
import com.fowo.api.common.util.DateUtils;
import com.fowo.api.common.util.ListUtils;
import com.fowo.api.common.util.ResponseUtils;
import com.fowo.api.common.util.SheetUtils;
import com.fowo.api.entity.NavSellOrder;
import com.fowo.api.flow.entity.WorkFlow;
import com.fowo.api.flow.service.WorkFlowService;
import com.fowo.api.mapper.NavLogisticsChannelViewMapper;
import com.fowo.api.mapper.NavLogisticsProviderViewMapper;
import com.fowo.api.mapper.NavSellOrderDeclareMapper;
import com.fowo.api.mapper.NavSellOrderDetailMapper;
import com.fowo.api.mapper.NavSellOrderMapper;
import com.fowo.api.mapper.NavSellOrderPlatformMapper;
import com.fowo.api.mapper.NavSellOrderTransactionMapper;
import com.fowo.api.mapper.ShopInfoMapper;
import com.fowo.api.mapper.SysCountryMapper;
import com.fowo.api.mapper.SysRegionMapper;
import com.fowo.api.mapper.WarehouseMapper;
import com.fowo.api.model.nav.logistics.channel.view.NavLogisticsChannelViewItemVo;
import com.fowo.api.model.nav.logistics.channel.view.NavLogisticsChannelViewSearchParamPo;
import com.fowo.api.model.nav.logistics.provider.view.NavLogisticsProviderViewItemVo;
import com.fowo.api.model.nav.logistics.provider.view.NavLogisticsProviderViewSearchParamPo;
import com.fowo.api.model.nav.sell.order.NavSellOrderChangeTagAction;
import com.fowo.api.model.nav.sell.order.NavSellOrderCreatePurchaseAction;
import com.fowo.api.model.nav.sell.order.NavSellOrderCutAction;
import com.fowo.api.model.nav.sell.order.NavSellOrderDeclareToProductAction;
import com.fowo.api.model.nav.sell.order.NavSellOrderDeliverAction;
import com.fowo.api.model.nav.sell.order.NavSellOrderExcelPo;
import com.fowo.api.model.nav.sell.order.NavSellOrderFreezeAction;
import com.fowo.api.model.nav.sell.order.NavSellOrderGetInventoryParam;
import com.fowo.api.model.nav.sell.order.NavSellOrderGetInventoryResult;
import com.fowo.api.model.nav.sell.order.NavSellOrderImportPo;
import com.fowo.api.model.nav.sell.order.NavSellOrderItemVo;
import com.fowo.api.model.nav.sell.order.NavSellOrderJoinAction;
import com.fowo.api.model.nav.sell.order.NavSellOrderJoinTaskAction;
import com.fowo.api.model.nav.sell.order.NavSellOrderLeaveMessageProcessedAction;
import com.fowo.api.model.nav.sell.order.NavSellOrderNoDeliverAction;
import com.fowo.api.model.nav.sell.order.NavSellOrderPickingDeliverAction;
import com.fowo.api.model.nav.sell.order.NavSellOrderProcessAction;
import com.fowo.api.model.nav.sell.order.NavSellOrderSearchParamPo;
import com.fowo.api.model.nav.sell.order.NavSellOrderSelectCostPriceParam;
import com.fowo.api.model.nav.sell.order.NavSellOrderSelectCostPriceResult;
import com.fowo.api.model.nav.sell.order.NavSellOrderSelectJoinOrderResult;
import com.fowo.api.model.nav.sell.order.NavSellOrderSelectNoPariOrderIdListParam;
import com.fowo.api.model.nav.sell.order.NavSellOrderSelectNoPariOrderIdListResult;
import com.fowo.api.model.nav.sell.order.NavSellOrderSelectPariListParam;
import com.fowo.api.model.nav.sell.order.NavSellOrderSelectPariListResult;
import com.fowo.api.model.nav.sell.order.NavSellOrderSelectPrintDetailParam;
import com.fowo.api.model.nav.sell.order.NavSellOrderSelectPrintDetailResult;
import com.fowo.api.model.nav.sell.order.NavSellOrderSelectPrintParam;
import com.fowo.api.model.nav.sell.order.NavSellOrderSelectPrintResult;
import com.fowo.api.model.nav.sell.order.NavSellOrderSelectProductParam;
import com.fowo.api.model.nav.sell.order.NavSellOrderSelectProductResult;
import com.fowo.api.model.nav.sell.order.NavSellOrderSelectSplitOrderResult;
import com.fowo.api.model.nav.sell.order.NavSellOrderSelectTagCountResult;
import com.fowo.api.model.nav.sell.order.NavSellOrderSplitTaskAction;
import com.fowo.api.model.nav.sell.order.NavSellOrderUnFreezeAction;
import com.fowo.api.model.nav.sell.order.NavSellOrderVo;
import com.fowo.api.model.nav.sell.order.declare.NavSellOrderDeclareSearchParamPo;
import com.fowo.api.model.nav.sell.order.detail.NavSellOrderDetailItemVo;
import com.fowo.api.model.nav.sell.order.detail.NavSellOrderDetailItemVoPages;
import com.fowo.api.model.nav.sell.order.detail.NavSellOrderDetailSearchParamPo;
import com.fowo.api.model.nav.sell.order.platform.NavSellOrderPlatformSearchParamPo;
import com.fowo.api.model.nav.sell.order.transaction.NavSellOrderTransactionSearchParamPo;
import com.fowo.api.model.shop.info.ShopInfoItemVo;
import com.fowo.api.model.shop.info.ShopInfoSearchParamPo;
import com.fowo.api.model.sys.country.SysCountryItemVo;
import com.fowo.api.model.sys.country.SysCountrySearchParamPo;
import com.fowo.api.model.sys.region.SysRegionItemVo;
import com.fowo.api.model.sys.region.SysRegionSearchParamPo;
import com.fowo.api.model.warehouse.WarehouseItemVo;
import com.fowo.api.model.warehouse.WarehouseSearchParamPo;
import com.fowo.api.service.NavSellOrderDeclareService;
import com.fowo.api.service.NavSellOrderDetailService;
import com.fowo.api.service.NavSellOrderPlatformService;
import com.fowo.api.service.NavSellOrderService;
import com.fowo.api.service.NavSellOrderTransactionService;
import com.fowo.api.sys.annotation.DataActivity;
import com.fowo.api.sys.component.SysDataActivityAopHelper;
import com.fowo.api.sys.entity.SysFile;
import com.fowo.api.sys.entity.SysImportTemplate;
import com.fowo.api.sys.entity.enums.SysDataActivityAction;
import com.fowo.api.sys.model.NewSerialRequest;
import com.fowo.api.sys.model.SysDictAllItem;
import com.fowo.api.sys.service.FileService;
import com.fowo.api.sys.service.SysDictService;
import com.fowo.api.sys.service.SysImportTemplateService;
import com.fowo.api.sys.service.SysSerialService;
import com.fowo.api.sys.ssf.SimpleStatusFlowService;
import com.fowo.api.user.model.JwtUserInfo;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

/**
 * 订单管理 服务实现基类
 * @author 蜂窝蜜造平台 配置人：任凯
 */
@Slf4j
@DataObjectType(NavSellOrder.class)
@DS("ds24")
public class NavSellOrderBaseServiceImpl
  extends ServiceImpl<NavSellOrderMapper, NavSellOrder>
  implements NavSellOrderService {

  /** 引用字段排序字段名转换信息 */
  public static final Map<String, String> SORT_FIELD_MAP = new HashMap<>() {
    {
      put("shopInfoShopName", "si.`shop_name`");
      put("siteName", "sr.`name`");
      put("createUserName", "su.`name`");
      put("deliveryLogisticsLabel", "nlpv.`label`");
      put("deliveryCountryCountry", "sc.`country`");
      put("deliveryWarehouseName", "w.`name`");
      put("deliveryLogisticsChannelLabel", "nlcv.`label`");
    }
  };
  // 导出时单次查询最大记录数
  protected static final int EXPORT_QUERY_MAX_SIZE = 1000;
  // 支持导出的最大记录数(1048576 为 Excel 支持的最大行数)
  protected static final long EXPORT_MAX_SIZE = 1048575;

  /**
   * 服务自引用，用于调用服务方法时包括 AOP 处理
   */
  @Resource
  protected NavSellOrderService self;

  @Resource
  protected NavSellOrderPlatformService navSellOrderPlatformService;

  @Resource
  protected NavSellOrderTransactionService navSellOrderTransactionService;

  @Resource
  protected NavSellOrderDetailService navSellOrderDetailService;

  @Resource
  protected NavSellOrderDeclareService navSellOrderDeclareService;

  @Resource
  protected SimpleStatusFlowService simpleStatusService;

  @Resource
  protected SysSerialService sysSerialService;

  @Resource
  private SysDictService sysDictService;

  @Resource
  protected ShopInfoMapper shopInfoMapper;

  @Resource
  protected SysRegionMapper sysRegionMapper;

  @Resource
  protected NavLogisticsProviderViewMapper navLogisticsProviderViewMapper;

  @Resource
  protected SysCountryMapper sysCountryMapper;

  @Resource
  protected WarehouseMapper warehouseMapper;

  @Resource
  protected NavLogisticsChannelViewMapper navLogisticsChannelViewMapper;

  @Resource
  protected FileService fileService;

  @Resource
  protected SysImportTemplateService importTemplateService;

  @Resource
  private CustomExcelExport customExcelExport;

  @Resource
  protected WorkFlowService workFlowService;

  @Autowired(required = false)
  protected NavSellOrderProcessAction navSellOrderProcessAction;

  @Autowired(required = false)
  protected NavSellOrderDeliverAction navSellOrderDeliverAction;

  @Autowired(required = false)
  protected NavSellOrderCutAction navSellOrderCutAction;

  @Autowired(required = false)
  protected NavSellOrderCreatePurchaseAction navSellOrderCreatePurchaseAction;

  @Autowired(required = false)
  protected NavSellOrderJoinTaskAction navSellOrderJoinTaskAction;

  @Autowired(required = false)
  protected NavSellOrderSplitTaskAction navSellOrderSplitTaskAction;

  @Autowired(required = false)
  protected NavSellOrderDeclareToProductAction navSellOrderDeclareToProductAction;

  @Autowired(required = false)
  protected NavSellOrderNoDeliverAction navSellOrderNoDeliverAction;

  @Autowired(required = false)
  protected NavSellOrderFreezeAction navSellOrderFreezeAction;

  @Autowired(required = false)
  protected NavSellOrderUnFreezeAction navSellOrderUnFreezeAction;

  @Autowired(required = false)
  protected NavSellOrderChangeTagAction navSellOrderChangeTagAction;

  @Autowired(required = false)
  protected NavSellOrderJoinAction navSellOrderJoinAction;

  @Autowired(required = false)
  protected NavSellOrderLeaveMessageProcessedAction navSellOrderLeaveMessageProcessedAction;

  @Autowired(required = false)
  protected NavSellOrderPickingDeliverAction navSellOrderPickingDeliverAction;

  @Resource
  protected Validator validator;

  /**
   * 创建订单管理
   * @param model 订单管理
   * @return 新数据的主键
   */
  @DataActivity(action = SysDataActivityAction.Add)
  @Transactional(rollbackFor = Exception.class)
  @Override
  public Long create(NavSellOrderVo model) throws Exception {
    JwtUserInfo currentUser = JwtUserInfo.fromHeader();
    NavSellOrder entity = new NavSellOrder();
    BeanUtils.copyProperties(model, entity);
    entity.setCreateTime(new Date());
    entity.setLastUpdateTime(new Date());
    if (currentUser != null) {
      entity.setCreateUser(currentUser.getUserId());
      entity.setLastUpdateUser(currentUser.getUserId());
    }

    if (model.getStatus() == null) {
      entity.setStatus("1");
    }

    if (model.getWarehouseActInventoryDeductionType() == null) {
      entity.setWarehouseActInventoryDeductionType("3");
    }

    if (model.getIssuActRules() == null) {
      entity.setIssuActRules("0");
    }

    if (model.getPariLike() == null) {
      entity.setPariLike("0");
    }
    // 填充序列号
    if (!StringUtils.hasText(entity.getOrderId())) {
      entity.setOrderId(
        sysSerialService.getNewSerial(
          new NewSerialRequest(null, "NavSellOrder.orderId")
        )
      );
    }
    if (this.save(entity)) {
      model.setId(entity.getId());
      updateAllChilds(model);
      simpleStatusService.afterCreate(
        "NavSellOrder",
        currentUser == null ? "" : currentUser.getDisplayName(),
        entity.getId(),
        entity.getStatus()
      );
      return entity.getId();
    }
    throw new Exception("订单管理保存失败");
  }

  /**
   * 更新所有子表
   * @param model 订单管理
   */
  protected void updateAllChilds(NavSellOrderVo model) throws Exception {
    if (model.getPlatform() != null) {
      navSellOrderPlatformService.saveAllByParentNavSellOrder(
        model.getId(),
        model.getPlatform()
      );
    }

    if (model.getTransaction() != null) {
      navSellOrderTransactionService.saveAllByParentNavSellOrder(
        model.getId(),
        model.getTransaction()
      );
    }

    if (model.getProduct() != null) {
      navSellOrderDetailService.saveAllByParentNavSellOrder(
        model.getId(),
        model.getProduct()
      );
    }

    if (model.getDeclare() != null) {
      navSellOrderDeclareService.saveAllByParentNavSellOrder(
        model.getId(),
        model.getDeclare()
      );
    }
  }

  /**
   * 更新订单管理
   * @param model 订单管理
   * @return 更新是否成功
   */
  @DataActivity(action = SysDataActivityAction.Modified)
  @Override
  @Transactional(rollbackFor = Exception.class)
  public boolean update(NavSellOrderVo model) throws Exception {
    JwtUserInfo currentUser = JwtUserInfo.fromHeader();
    NavSellOrder entity = this.getById(model.getId());
    if (entity == null) {
      throw new Exception("订单管理不存在");
    }
    // 获取简单状态
    String rawSimpleStatus = entity.getStatus();
    BeanUtils.copyProperties(
      model,
      entity,
      "id",
      "orderId",
      "lastUpdateTime",
      "createUser",
      "lastUpdateUser",
      "createTime"
    );
    entity.setLastUpdateTime(new Date());
    if (currentUser != null) {
      entity.setLastUpdateUser(currentUser.getUserId());
    }
    if (this.updateById(entity)) {
      updateAllChilds(model);
      // 简单流程状态更新
      if (model.getStatus() != null) {
        simpleStatusService.afterUpdate(
          "NavSellOrder",
          currentUser == null ? "" : currentUser.getDisplayName(),
          entity.getId(),
          rawSimpleStatus,
          model.getStatus()
        );
      }

      return true;
    }
    return false;
  }/**
   * 更新订单管理（带空值）
   * @param model 订单管理
   * @return 更新是否成功
   */

  @DataActivity(action = SysDataActivityAction.Modified)
  @Override
  @Transactional(rollbackFor = Exception.class)
  public boolean updateForEdit(NavSellOrderVo model) throws Exception {
    JwtUserInfo currentUser = JwtUserInfo.fromHeader();
    NavSellOrder entity = this.getById(model.getId());
    if (entity == null) {
      throw new Exception("订单管理不存在");
    }
    model.setLastUpdateTime(new Date());
    if (currentUser != null) {
      model.setLastUpdateUser(currentUser.getUserId());
    }
    boolean isOk = new LambdaUpdateChainWrapper<>(baseMapper)
      .set(NavSellOrder::getShopInfo, model.getShopInfo())
      .set(NavSellOrder::getCurrency, model.getCurrency())
      .set(NavSellOrder::getType, model.getType())
      .set(NavSellOrder::getStatus, model.getStatus())
      .set(NavSellOrder::getSite, model.getSite())
      .set(NavSellOrder::getTag, model.getTag())
      .set(NavSellOrder::getSource, model.getSource())
      .set(
        model.getFiles() != null,
        NavSellOrder::getFiles,
        JSON.toJSONString(model.getFiles())
      )
      .setSql(model.getFiles() == null, "files = null")
      .set(NavSellOrder::getLastUpdateTime, model.getLastUpdateTime())
      .set(NavSellOrder::getSplitType, model.getSplitType())
      .set(NavSellOrder::getRemark, model.getRemark())
      .set(NavSellOrder::getLastUpdateUser, model.getLastUpdateUser())
      .set(NavSellOrder::getPaymentWay, model.getPaymentWay())
      .set(NavSellOrder::getBuyerName, model.getBuyerName())
      .set(NavSellOrder::getBuyerEmail, model.getBuyerEmail())
      .set(NavSellOrder::getDeliveryLogistics, model.getDeliveryLogistics())
      .set(NavSellOrder::getBuyerLeaveWord, model.getBuyerLeaveWord())
      .set(NavSellOrder::getDeliveryReceipt, model.getDeliveryReceipt())
      .set(NavSellOrder::getDeliveryZipCode, model.getDeliveryZipCode())
      .set(NavSellOrder::getDeliveryPhone, model.getDeliveryPhone())
      .set(NavSellOrder::getDeliveryCountry, model.getDeliveryCountry())
      .set(NavSellOrder::getDeliveryProvince, model.getDeliveryProvince())
      .set(NavSellOrder::getDeliveryCity, model.getDeliveryCity())
      .set(NavSellOrder::getDeliveryArea, model.getDeliveryArea())
      .set(NavSellOrder::getDeliveryHouseNumber, model.getDeliveryHouseNumber())
      .set(NavSellOrder::getDeliveryCompany, model.getDeliveryCompany())
      .set(NavSellOrder::getDeliveryAddressType, model.getDeliveryAddressType())
      .set(NavSellOrder::getDeliveryAddress1, model.getDeliveryAddress1())
      .set(NavSellOrder::getDeliveryAddress2, model.getDeliveryAddress2())
      .set(NavSellOrder::getDeliveryAddress3, model.getDeliveryAddress3())
      .set(NavSellOrder::getDeliveryWidType, model.getDeliveryWidType())
      .set(NavSellOrder::getDeliveryWarehouse, model.getDeliveryWarehouse())
      .set(
        NavSellOrder::getDeliveryLogisticsChannel,
        model.getDeliveryLogisticsChannel()
      )
      .set(NavSellOrder::getDeliveryWaybillId, model.getDeliveryWaybillId())
      .set(NavSellOrder::getDeliveryTrackId, model.getDeliveryTrackId())
      .set(
        NavSellOrder::getDeliveryPartnerOrderId,
        model.getDeliveryPartnerOrderId()
      )
      .set(NavSellOrder::getDeliveryIssuId, model.getDeliveryIssuId())
      .set(NavSellOrder::getDeliveryType, model.getDeliveryType())
      .set(NavSellOrder::getDeliveryTime, model.getDeliveryTime())
      .set(NavSellOrder::getIssuTime, model.getIssuTime())
      .set(
        NavSellOrder::getDeliveryRecipientTaxType,
        model.getDeliveryRecipientTaxType()
      )
      .set(
        NavSellOrder::getDeliveryRecipientTaxNo,
        model.getDeliveryRecipientTaxNo()
      )
      .set(
        NavSellOrder::getDeliveryRecipientIdentityNo,
        model.getDeliveryRecipientIdentityNo()
      )
      .set(
        NavSellOrder::getDeliverySenderTaxNoType,
        model.getDeliverySenderTaxNoType()
      )
      .set(NavSellOrder::getDeliverySenderTaxNo, model.getDeliverySenderTaxNo())
      .set(NavSellOrder::getDeliveryCodeOrder, model.getDeliveryCodeOrder())
      .set(
        NavSellOrder::getDeliveryThinkFreight,
        model.getDeliveryThinkFreight()
      )
      .set(
        NavSellOrder::getDeliveryThinkWeightUnit,
        model.getDeliveryThinkWeightUnit()
      )
      .set(NavSellOrder::getDeliveryThinkWeight, model.getDeliveryThinkWeight())
      .set(
        NavSellOrder::getDeliveryThinkSizeUnit,
        model.getDeliveryThinkSizeUnit()
      )
      .set(
        NavSellOrder::getDeliveryThinkSizeLength,
        model.getDeliveryThinkSizeLength()
      )
      .set(
        NavSellOrder::getDeliveryThinkSizeWidth,
        model.getDeliveryThinkSizeWidth()
      )
      .set(
        NavSellOrder::getDeliveryThinkSizeHeight,
        model.getDeliveryThinkSizeHeight()
      )
      .set(
        NavSellOrder::getDeliveryThinkVolumeUnit,
        model.getDeliveryThinkVolumeUnit()
      )
      .set(NavSellOrder::getDeliveryThinkVolume, model.getDeliveryThinkVolume())
      .set(
        NavSellOrder::getDeliveryThinkFeeWeightUnit,
        model.getDeliveryThinkFeeWeightUnit()
      )
      .set(
        NavSellOrder::getDeliveryThinkFeeWeight,
        model.getDeliveryThinkFeeWeight()
      )
      .set(
        NavSellOrder::getDeliveryRealWeightUnit,
        model.getDeliveryRealWeightUnit()
      )
      .set(NavSellOrder::getDeliveryRealWeight, model.getDeliveryRealWeight())
      .set(
        NavSellOrder::getDeliveryRealSizeUnit,
        model.getDeliveryRealSizeUnit()
      )
      .set(
        NavSellOrder::getDeliveryRealSizeLength,
        model.getDeliveryRealSizeLength()
      )
      .set(
        NavSellOrder::getDeliveryRealSizeWidth,
        model.getDeliveryRealSizeWidth()
      )
      .set(
        NavSellOrder::getDeliveryRealSizeHeight,
        model.getDeliveryRealSizeHeight()
      )
      .set(
        NavSellOrder::getDeliveryRealVolumeUnit,
        model.getDeliveryRealVolumeUnit()
      )
      .set(NavSellOrder::getDeliveryRealVolume, model.getDeliveryRealVolume())
      .set(
        NavSellOrder::getDeliveryRealFeeWeightUnit,
        model.getDeliveryRealFeeWeightUnit()
      )
      .set(
        NavSellOrder::getDeliveryRealFeeWeight,
        model.getDeliveryRealFeeWeight()
      )
      .set(
        NavSellOrder::getDeliveryRealQuantity,
        model.getDeliveryRealQuantity()
      )
      .set(
        NavSellOrder::getDeliveryRealCurrencyCode,
        model.getDeliveryRealCurrencyCode()
      )
      .set(NavSellOrder::getDeliveryRealFreight, model.getDeliveryRealFreight())
      .set(NavSellOrder::getDeliveryStatus, model.getDeliveryStatus())
      .set(NavSellOrder::getDeliveryMessage, model.getDeliveryMessage())
      .set(NavSellOrder::getDeliveryRemark, model.getDeliveryRemark())
      .set(NavSellOrder::getProcessTime, model.getProcessTime())
      .set(NavSellOrder::getDistributionTime, model.getDistributionTime())
      .set(NavSellOrder::getPickingTime, model.getPickingTime())
      .set(NavSellOrder::getTailTime, model.getTailTime())
      .set(NavSellOrder::getCutStatus, model.getCutStatus())
      .set(NavSellOrder::getDistributionStatus, model.getDistributionStatus())
      .set(NavSellOrder::getPrintFaceStatus, model.getPrintFaceStatus())
      .set(NavSellOrder::getPrintOrderStatus, model.getPrintOrderStatus())
      .set(NavSellOrder::getIsTest, model.getIsTest())
      .set(NavSellOrder::getIsWeigh, model.getIsWeigh())
      .set(NavSellOrder::getWoNumber, model.getWoNumber())
      .set(NavSellOrder::getWmsOrderId, model.getWmsOrderId())
      .set(NavSellOrder::getBoxId, model.getBoxId())
      .set(NavSellOrder::getIssuStatusExplain, model.getIssuStatusExplain())
      .set(NavSellOrder::getIssuActRules, model.getIssuActRules())
      .eq(NavSellOrder::getId, model.getId())
      .update();
    if (isOk) {
      updateAllChilds(model);
      // 更新简单状态流程
      if (model.getStatus() != null) {
        simpleStatusService.afterUpdate(
          "NavSellOrder",
          currentUser == null ? "" : currentUser.getDisplayName(),
          entity.getId(),
          entity.getStatus(),
          model.getStatus()
        );
      }
    }
    return isOk;
  }

  /**
   * 是否走导出中心
   */
  @Override
  public boolean getBackgroundExportFlag(NavSellOrderSearchParamPo search) {
    return false;
  }

  /**
   * 批量删除指定主键列表关联的所有子表数据(此方法不包括事务，必须由其它已包括事务的方法调用)
   */
  protected void batchDeleteChilds(List<Long> ids) throws Exception {
    // 处理子表字段 平台信息(platform) 对应的对象
    NavSellOrderPlatformSearchParamPo platformSearchParam =
      new NavSellOrderPlatformSearchParamPo();
    platformSearchParam.setDisableDataPremissions(true);
    platformSearchParam.setParentNavSellOrderInList(ids);
    NavSellOrderPlatformMapper localNavSellOrderPlatformMapper = ContextHolder
      .getApplicationContext()
      .getBean(NavSellOrderPlatformMapper.class);
    platformSearchParam.applySqlSegments();
    List<Long> platformIdList = localNavSellOrderPlatformMapper.searchIds(
      platformSearchParam
    );
    if (!platformIdList.isEmpty()) {
      NavSellOrderPlatformService localNavSellOrderPlatformService =
        ContextHolder
          .getApplicationContext()
          .getBean(NavSellOrderPlatformService.class);
      localNavSellOrderPlatformService.batchDelete(platformIdList);
    }

    // 处理子表字段 交易信息(transaction) 对应的对象
    NavSellOrderTransactionSearchParamPo transactionSearchParam =
      new NavSellOrderTransactionSearchParamPo();
    transactionSearchParam.setDisableDataPremissions(true);
    transactionSearchParam.setParentNavSellOrderInList(ids);
    NavSellOrderTransactionMapper localNavSellOrderTransactionMapper =
      ContextHolder
        .getApplicationContext()
        .getBean(NavSellOrderTransactionMapper.class);
    transactionSearchParam.applySqlSegments();
    List<Long> transactionIdList = localNavSellOrderTransactionMapper.searchIds(
      transactionSearchParam
    );
    if (!transactionIdList.isEmpty()) {
      NavSellOrderTransactionService localNavSellOrderTransactionService =
        ContextHolder
          .getApplicationContext()
          .getBean(NavSellOrderTransactionService.class);
      localNavSellOrderTransactionService.batchDelete(transactionIdList);
    }

    // 处理子表字段 产品信息(product) 对应的对象
    NavSellOrderDetailSearchParamPo productSearchParam =
      new NavSellOrderDetailSearchParamPo();
    productSearchParam.setDisableDataPremissions(true);
    productSearchParam.setParentNavSellOrderInList(ids);
    NavSellOrderDetailMapper localNavSellOrderDetailMapper = ContextHolder
      .getApplicationContext()
      .getBean(NavSellOrderDetailMapper.class);
    productSearchParam.applySqlSegments();
    List<Long> productIdList = localNavSellOrderDetailMapper.searchIds(
      productSearchParam
    );
    if (!productIdList.isEmpty()) {
      NavSellOrderDetailService localNavSellOrderDetailService = ContextHolder
        .getApplicationContext()
        .getBean(NavSellOrderDetailService.class);
      localNavSellOrderDetailService.batchDelete(productIdList);
    }

    // 处理子表字段 报关信息(declare) 对应的对象
    NavSellOrderDeclareSearchParamPo declareSearchParam =
      new NavSellOrderDeclareSearchParamPo();
    declareSearchParam.setDisableDataPremissions(true);
    declareSearchParam.setParentNavSellOrderInList(ids);
    NavSellOrderDeclareMapper localNavSellOrderDeclareMapper = ContextHolder
      .getApplicationContext()
      .getBean(NavSellOrderDeclareMapper.class);
    declareSearchParam.applySqlSegments();
    List<Long> declareIdList = localNavSellOrderDeclareMapper.searchIds(
      declareSearchParam
    );
    if (!declareIdList.isEmpty()) {
      NavSellOrderDeclareService localNavSellOrderDeclareService = ContextHolder
        .getApplicationContext()
        .getBean(NavSellOrderDeclareService.class);
      localNavSellOrderDeclareService.batchDelete(declareIdList);
    }
  }

  /**
   * 删除订单管理
   * @param id 订单管理的主键
   * @return 删除是否成功
   */
  @DataActivity(action = SysDataActivityAction.Del)
  @Override
  public boolean delete(Long id) throws Exception {
    batchDeleteChilds(Collections.singletonList(id));
    return this.removeById(id);
  }

  /**
   * 批量删除订单管理
   * @param ids 订单管理的主键列表
   * @return 删除是否成功
   */
  @DataActivity(action = SysDataActivityAction.Del)
  @Override
  public boolean batchDelete(List<Long> ids) throws Exception {
    batchDeleteChilds(ids);

    int count = 0;
    for (int i = 0; i < ids.size(); i += 2000) {
      count +=
        baseMapper.deleteBatchIds(
          ids.stream().skip(i).limit(2000).collect(Collectors.toList())
        );
    }
    return count > 0;
  }

  /**
   * 导入单行处理
   * @param row 要导入的行
   * @param rowNumber 所在行号
   * @param vo 输出VO,可空
   * @param variables 变量池，用于在一次导入过程中保存临时信息
   * @param allowOverrides 允许覆盖
   * @return 导入行对象
   */
  protected ImportRow<NavSellOrderImportPo> excelToImportRow(
    NavSellOrderImportPo row,
    Integer rowNumber,
    NavSellOrderVo vo,
    Map<String, Object> variables,
    boolean allowOverrides
  ) {
    ImportRow<NavSellOrderImportPo> ir = new ImportRow<NavSellOrderImportPo>();
    ir.setRowNumber(rowNumber);
    ir.setRow(row);
    if (SheetUtils.isAllFieldsEmpty(row)) {
      ir.setEmptyRow(true);
      ir.addError("", "空行");
      return ir;
    }
    final Set<ConstraintViolation<NavSellOrderImportPo>> validate =
      validator.validate(row);
    boolean isOutputVo = vo != null;
    if (!isOutputVo) {
      vo = new NavSellOrderVo();
    }
    BeanUtils.copyProperties(row, vo);
    // 收集基本校验错误
    ir.initErrors(validate, NavSellOrderImportPo.class);

    // 一般数据处理
    if (StringUtils.hasText(row.getCurrency())) {
      List<SysDictAllItem> currencyItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "currency",
          n -> sysDictService.getDictItems("SCM00015")
        );
      NavSellOrderVo finalVo = vo;
      currencyItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getCurrency()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setCurrency(i.getItemValue()),
          () ->
            ir.addError(
              "currency",
              String.format(
                "必须为 %s 中之一",
                currencyItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getType())) {
      List<SysDictAllItem> typeItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "type",
          n -> sysDictService.getDictItems("SCM00122")
        );
      NavSellOrderVo finalVo = vo;
      typeItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getType()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setType(i.getItemValue()),
          () ->
            ir.addError(
              "type",
              String.format(
                "必须为 %s 中之一",
                typeItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getStatus())) {
      List<SysDictAllItem> statusItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "status",
          n -> sysDictService.getDictItems("SCM00143")
        );
      NavSellOrderVo finalVo = vo;
      statusItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getStatus()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setStatus(i.getItemValue()),
          () ->
            ir.addError(
              "status",
              String.format(
                "必须为 %s 中之一",
                statusItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getTag())) {
      List<SysDictAllItem> tagItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "tag",
          n -> sysDictService.getDictItems("SCM00142")
        );
      NavSellOrderVo finalVo = vo;
      List<String> tagTexts = Arrays
        .stream(row.getTag().split(","))
        .filter(StringUtils::hasText)
        .collect(Collectors.toList());
      finalVo.setTag(
        tagItems
          .stream()
          .filter(i -> tagTexts.contains(i.getItemText()))
          .map(SysDictAllItem::getItemValue)
          .collect(Collectors.joining(","))
      );
    }
    if (StringUtils.hasText(row.getSource())) {
      List<SysDictAllItem> sourceItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "source",
          n -> sysDictService.getDictItems("SCM00121")
        );
      NavSellOrderVo finalVo = vo;
      sourceItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getSource()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setSource(i.getItemValue()),
          () ->
            ir.addError(
              "source",
              String.format(
                "必须为 %s 中之一",
                sourceItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getSplitType())) {
      List<SysDictAllItem> splitTypeItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "splitType",
          n -> sysDictService.getDictItems("SCM00183")
        );
      NavSellOrderVo finalVo = vo;
      splitTypeItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getSplitType()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setSplitType(i.getItemValue()),
          () ->
            ir.addError(
              "splitType",
              String.format(
                "必须为 %s 中之一",
                splitTypeItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getPaymentWay())) {
      List<SysDictAllItem> paymentWayItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "paymentWay",
          n -> sysDictService.getDictItems("SCM00144")
        );
      NavSellOrderVo finalVo = vo;
      paymentWayItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getPaymentWay()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setPaymentWay(i.getItemValue()),
          () ->
            ir.addError(
              "paymentWay",
              String.format(
                "必须为 %s 中之一",
                paymentWayItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getDeliveryAddressType())) {
      List<SysDictAllItem> deliveryAddressTypeItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliveryAddressType",
          n -> sysDictService.getDictItems("SCM00124")
        );
      NavSellOrderVo finalVo = vo;
      deliveryAddressTypeItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliveryAddressType()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliveryAddressType(i.getItemValue()),
          () ->
            ir.addError(
              "deliveryAddressType",
              String.format(
                "必须为 %s 中之一",
                deliveryAddressTypeItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getDeliveryWidType())) {
      List<SysDictAllItem> deliveryWidTypeItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliveryWidType",
          n -> sysDictService.getDictItems("SCM00017")
        );
      NavSellOrderVo finalVo = vo;
      deliveryWidTypeItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliveryWidType()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliveryWidType(i.getItemValue()),
          () ->
            ir.addError(
              "deliveryWidType",
              String.format(
                "必须为 %s 中之一",
                deliveryWidTypeItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getDeliveryType())) {
      List<SysDictAllItem> deliveryTypeItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliveryType",
          n -> sysDictService.getDictItems("SCM00184")
        );
      NavSellOrderVo finalVo = vo;
      deliveryTypeItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliveryType()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliveryType(i.getItemValue()),
          () ->
            ir.addError(
              "deliveryType",
              String.format(
                "必须为 %s 中之一",
                deliveryTypeItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    vo.setDeliveryTime(SheetUtils.tryToDateTime(row.getDeliveryTime()));
    vo.setIssuTime(SheetUtils.tryToDateTime(row.getIssuTime()));
    if (StringUtils.hasText(row.getDeliveryRecipientTaxType())) {
      List<SysDictAllItem> deliveryRecipientTaxTypeItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliveryRecipientTaxType",
          n -> sysDictService.getDictItems("SCM00141")
        );
      NavSellOrderVo finalVo = vo;
      deliveryRecipientTaxTypeItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliveryRecipientTaxType()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliveryRecipientTaxType(i.getItemValue()),
          () ->
            ir.addError(
              "deliveryRecipientTaxType",
              String.format(
                "必须为 %s 中之一",
                deliveryRecipientTaxTypeItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getDeliverySenderTaxNoType())) {
      List<SysDictAllItem> deliverySenderTaxNoTypeItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliverySenderTaxNoType",
          n -> sysDictService.getDictItems("SCM00141")
        );
      NavSellOrderVo finalVo = vo;
      deliverySenderTaxNoTypeItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliverySenderTaxNoType()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliverySenderTaxNoType(i.getItemValue()),
          () ->
            ir.addError(
              "deliverySenderTaxNoType",
              String.format(
                "必须为 %s 中之一",
                deliverySenderTaxNoTypeItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getDeliveryCodeOrder())) {
      List<SysDictAllItem> deliveryCodeOrderItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliveryCodeOrder",
          n -> sysDictService.getDictItems("SCM00008")
        );
      NavSellOrderVo finalVo = vo;
      deliveryCodeOrderItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliveryCodeOrder()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliveryCodeOrder(i.getItemValue()),
          () ->
            ir.addError(
              "deliveryCodeOrder",
              String.format(
                "必须为 %s 中之一",
                deliveryCodeOrderItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    vo.setDeliveryThinkFreight(
      SheetUtils.tryToDecimal(row.getDeliveryThinkFreight())
    );
    if (StringUtils.hasText(row.getDeliveryThinkWeightUnit())) {
      List<SysDictAllItem> deliveryThinkWeightUnitItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliveryThinkWeightUnit",
          n -> sysDictService.getDictItems("SCM00113")
        );
      NavSellOrderVo finalVo = vo;
      deliveryThinkWeightUnitItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliveryThinkWeightUnit()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliveryThinkWeightUnit(i.getItemValue()),
          () ->
            ir.addError(
              "deliveryThinkWeightUnit",
              String.format(
                "必须为 %s 中之一",
                deliveryThinkWeightUnitItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    vo.setDeliveryThinkWeight(
      SheetUtils.tryToDecimal(row.getDeliveryThinkWeight())
    );
    if (StringUtils.hasText(row.getDeliveryThinkSizeUnit())) {
      List<SysDictAllItem> deliveryThinkSizeUnitItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliveryThinkSizeUnit",
          n -> sysDictService.getDictItems("SCM00146")
        );
      NavSellOrderVo finalVo = vo;
      deliveryThinkSizeUnitItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliveryThinkSizeUnit()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliveryThinkSizeUnit(i.getItemValue()),
          () ->
            ir.addError(
              "deliveryThinkSizeUnit",
              String.format(
                "必须为 %s 中之一",
                deliveryThinkSizeUnitItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    vo.setDeliveryThinkSizeLength(
      SheetUtils.tryToDecimal(row.getDeliveryThinkSizeLength())
    );
    vo.setDeliveryThinkSizeWidth(
      SheetUtils.tryToDecimal(row.getDeliveryThinkSizeWidth())
    );
    vo.setDeliveryThinkSizeHeight(
      SheetUtils.tryToDecimal(row.getDeliveryThinkSizeHeight())
    );
    if (StringUtils.hasText(row.getDeliveryThinkVolumeUnit())) {
      List<SysDictAllItem> deliveryThinkVolumeUnitItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliveryThinkVolumeUnit",
          n -> sysDictService.getDictItems("SCM00147")
        );
      NavSellOrderVo finalVo = vo;
      deliveryThinkVolumeUnitItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliveryThinkVolumeUnit()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliveryThinkVolumeUnit(i.getItemValue()),
          () ->
            ir.addError(
              "deliveryThinkVolumeUnit",
              String.format(
                "必须为 %s 中之一",
                deliveryThinkVolumeUnitItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    vo.setDeliveryThinkVolume(
      SheetUtils.tryToDecimal(row.getDeliveryThinkVolume())
    );
    if (StringUtils.hasText(row.getDeliveryThinkFeeWeightUnit())) {
      List<SysDictAllItem> deliveryThinkFeeWeightUnitItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliveryThinkFeeWeightUnit",
          n -> sysDictService.getDictItems("SCM00113")
        );
      NavSellOrderVo finalVo = vo;
      deliveryThinkFeeWeightUnitItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliveryThinkFeeWeightUnit())
        )
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliveryThinkFeeWeightUnit(i.getItemValue()),
          () ->
            ir.addError(
              "deliveryThinkFeeWeightUnit",
              String.format(
                "必须为 %s 中之一",
                deliveryThinkFeeWeightUnitItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    vo.setDeliveryThinkFeeWeight(
      SheetUtils.tryToDecimal(row.getDeliveryThinkFeeWeight())
    );
    if (StringUtils.hasText(row.getDeliveryRealWeightUnit())) {
      List<SysDictAllItem> deliveryRealWeightUnitItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliveryRealWeightUnit",
          n -> sysDictService.getDictItems("SCM00113")
        );
      NavSellOrderVo finalVo = vo;
      deliveryRealWeightUnitItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliveryRealWeightUnit()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliveryRealWeightUnit(i.getItemValue()),
          () ->
            ir.addError(
              "deliveryRealWeightUnit",
              String.format(
                "必须为 %s 中之一",
                deliveryRealWeightUnitItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    vo.setDeliveryRealWeight(
      SheetUtils.tryToDecimal(row.getDeliveryRealWeight())
    );
    if (StringUtils.hasText(row.getDeliveryRealSizeUnit())) {
      List<SysDictAllItem> deliveryRealSizeUnitItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliveryRealSizeUnit",
          n -> sysDictService.getDictItems("SCM00146")
        );
      NavSellOrderVo finalVo = vo;
      deliveryRealSizeUnitItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliveryRealSizeUnit()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliveryRealSizeUnit(i.getItemValue()),
          () ->
            ir.addError(
              "deliveryRealSizeUnit",
              String.format(
                "必须为 %s 中之一",
                deliveryRealSizeUnitItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    vo.setDeliveryRealSizeLength(
      SheetUtils.tryToDecimal(row.getDeliveryRealSizeLength())
    );
    vo.setDeliveryRealSizeWidth(
      SheetUtils.tryToDecimal(row.getDeliveryRealSizeWidth())
    );
    vo.setDeliveryRealSizeHeight(
      SheetUtils.tryToDecimal(row.getDeliveryRealSizeHeight())
    );
    if (StringUtils.hasText(row.getDeliveryRealVolumeUnit())) {
      List<SysDictAllItem> deliveryRealVolumeUnitItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliveryRealVolumeUnit",
          n -> sysDictService.getDictItems("SCM00147")
        );
      NavSellOrderVo finalVo = vo;
      deliveryRealVolumeUnitItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliveryRealVolumeUnit()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliveryRealVolumeUnit(i.getItemValue()),
          () ->
            ir.addError(
              "deliveryRealVolumeUnit",
              String.format(
                "必须为 %s 中之一",
                deliveryRealVolumeUnitItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    vo.setDeliveryRealVolume(
      SheetUtils.tryToDecimal(row.getDeliveryRealVolume())
    );
    if (StringUtils.hasText(row.getDeliveryRealFeeWeightUnit())) {
      List<SysDictAllItem> deliveryRealFeeWeightUnitItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliveryRealFeeWeightUnit",
          n -> sysDictService.getDictItems("SCM00113")
        );
      NavSellOrderVo finalVo = vo;
      deliveryRealFeeWeightUnitItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliveryRealFeeWeightUnit()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliveryRealFeeWeightUnit(i.getItemValue()),
          () ->
            ir.addError(
              "deliveryRealFeeWeightUnit",
              String.format(
                "必须为 %s 中之一",
                deliveryRealFeeWeightUnitItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    vo.setDeliveryRealFeeWeight(
      SheetUtils.tryToDecimal(row.getDeliveryRealFeeWeight())
    );
    vo.setDeliveryRealQuantity(
      SheetUtils.tryToInteger(row.getDeliveryRealQuantity())
    );
    if (StringUtils.hasText(row.getDeliveryRealCurrencyCode())) {
      List<SysDictAllItem> deliveryRealCurrencyCodeItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliveryRealCurrencyCode",
          n -> sysDictService.getDictItems("SCM00015")
        );
      NavSellOrderVo finalVo = vo;
      deliveryRealCurrencyCodeItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliveryRealCurrencyCode()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliveryRealCurrencyCode(i.getItemValue()),
          () ->
            ir.addError(
              "deliveryRealCurrencyCode",
              String.format(
                "必须为 %s 中之一",
                deliveryRealCurrencyCodeItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    vo.setDeliveryRealFreight(
      SheetUtils.tryToDecimal(row.getDeliveryRealFreight())
    );
    if (StringUtils.hasText(row.getDeliveryStatus())) {
      List<SysDictAllItem> deliveryStatusItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "deliveryStatus",
          n -> sysDictService.getDictItems("SCM00028")
        );
      NavSellOrderVo finalVo = vo;
      deliveryStatusItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDeliveryStatus()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDeliveryStatus(i.getItemValue()),
          () ->
            ir.addError(
              "deliveryStatus",
              String.format(
                "必须为 %s 中之一",
                deliveryStatusItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    vo.setProcessTime(SheetUtils.tryToDateTime(row.getProcessTime()));
    vo.setDistributionTime(SheetUtils.tryToDateTime(row.getDistributionTime()));
    vo.setPickingTime(SheetUtils.tryToDateTime(row.getPickingTime()));
    vo.setTailTime(SheetUtils.tryToDateTime(row.getTailTime()));
    if (StringUtils.hasText(row.getCutStatus())) {
      List<SysDictAllItem> cutStatusItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "cutStatus",
          n -> sysDictService.getDictItems("SCM00178")
        );
      NavSellOrderVo finalVo = vo;
      cutStatusItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getCutStatus()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setCutStatus(i.getItemValue()),
          () ->
            ir.addError(
              "cutStatus",
              String.format(
                "必须为 %s 中之一",
                cutStatusItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getDistributionStatus())) {
      List<SysDictAllItem> distributionStatusItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "distributionStatus",
          n -> sysDictService.getDictItems("SCM00161")
        );
      NavSellOrderVo finalVo = vo;
      distributionStatusItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getDistributionStatus()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setDistributionStatus(i.getItemValue()),
          () ->
            ir.addError(
              "distributionStatus",
              String.format(
                "必须为 %s 中之一",
                distributionStatusItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getPrintFaceStatus())) {
      List<SysDictAllItem> printFaceStatusItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "printFaceStatus",
          n -> sysDictService.getDictItems("SCM00008")
        );
      NavSellOrderVo finalVo = vo;
      printFaceStatusItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getPrintFaceStatus()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setPrintFaceStatus(i.getItemValue()),
          () ->
            ir.addError(
              "printFaceStatus",
              String.format(
                "必须为 %s 中之一",
                printFaceStatusItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getPrintOrderStatus())) {
      List<SysDictAllItem> printOrderStatusItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "printOrderStatus",
          n -> sysDictService.getDictItems("SCM00008")
        );
      NavSellOrderVo finalVo = vo;
      printOrderStatusItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getPrintOrderStatus()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setPrintOrderStatus(i.getItemValue()),
          () ->
            ir.addError(
              "printOrderStatus",
              String.format(
                "必须为 %s 中之一",
                printOrderStatusItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getIsTest())) {
      List<SysDictAllItem> isTestItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "isTest",
          n -> sysDictService.getDictItems("SCM00008")
        );
      NavSellOrderVo finalVo = vo;
      isTestItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getIsTest()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setIsTest(i.getItemValue()),
          () ->
            ir.addError(
              "isTest",
              String.format(
                "必须为 %s 中之一",
                isTestItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getIsWeigh())) {
      List<SysDictAllItem> isWeighItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "isWeigh",
          n -> sysDictService.getDictItems("SCM00008")
        );
      NavSellOrderVo finalVo = vo;
      isWeighItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getIsWeigh()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setIsWeigh(i.getItemValue()),
          () ->
            ir.addError(
              "isWeigh",
              String.format(
                "必须为 %s 中之一",
                isWeighItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    vo.setWmsOrderId(SheetUtils.tryToLong(row.getWmsOrderId()));
    vo.setPickingDeliveryTime(
      SheetUtils.tryToDateTime(row.getPickingDeliveryTime())
    );
    if (StringUtils.hasText(row.getWarehouseActInventoryDeductionType())) {
      List<SysDictAllItem> warehouseActInventoryDeductionTypeItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "warehouseActInventoryDeductionType",
          n -> sysDictService.getDictItems("SCM00127")
        );
      NavSellOrderVo finalVo = vo;
      warehouseActInventoryDeductionTypeItems
        .stream()
        .filter(i ->
          i.getItemText().equals(row.getWarehouseActInventoryDeductionType())
        )
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setWarehouseActInventoryDeductionType(i.getItemValue()),
          () ->
            ir.addError(
              "warehouseActInventoryDeductionType",
              String.format(
                "必须为 %s 中之一",
                warehouseActInventoryDeductionTypeItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getLogisticsOrderStatus())) {
      List<SysDictAllItem> logisticsOrderStatusItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "logisticsOrderStatus",
          n -> sysDictService.getDictItems("SCM00204")
        );
      NavSellOrderVo finalVo = vo;
      logisticsOrderStatusItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getLogisticsOrderStatus()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setLogisticsOrderStatus(i.getItemValue()),
          () ->
            ir.addError(
              "logisticsOrderStatus",
              String.format(
                "必须为 %s 中之一",
                logisticsOrderStatusItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getIssuStatus())) {
      List<SysDictAllItem> issuStatusItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "issuStatus",
          n -> sysDictService.getDictItems("SCM00160")
        );
      NavSellOrderVo finalVo = vo;
      issuStatusItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getIssuStatus()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setIssuStatus(i.getItemValue()),
          () ->
            ir.addError(
              "issuStatus",
              String.format(
                "必须为 %s 中之一",
                issuStatusItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    vo.setIssuNumber(SheetUtils.tryToInteger(row.getIssuNumber()));
    if (StringUtils.hasText(row.getIssuActRules())) {
      List<SysDictAllItem> issuActRulesItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "issuActRules",
          n -> sysDictService.getDictItems("SCM00133")
        );
      NavSellOrderVo finalVo = vo;
      issuActRulesItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getIssuActRules()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setIssuActRules(i.getItemValue()),
          () ->
            ir.addError(
              "issuActRules",
              String.format(
                "必须为 %s 中之一",
                issuActRulesItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    if (StringUtils.hasText(row.getPariLike())) {
      List<SysDictAllItem> pariLikeItems =
        (List<SysDictAllItem>) variables.computeIfAbsent(
          "pariLike",
          n -> sysDictService.getDictItems("SCM00008")
        );
      NavSellOrderVo finalVo = vo;
      pariLikeItems
        .stream()
        .filter(i -> i.getItemText().equals(row.getPariLike()))
        .findFirst()
        .ifPresentOrElse(
          i -> finalVo.setPariLike(i.getItemValue()),
          () ->
            ir.addError(
              "pariLike",
              String.format(
                "必须为 %s 中之一",
                pariLikeItems
                  .stream()
                  .map(SysDictAllItem::getItemText)
                  .collect(Collectors.joining(", "))
              )
            )
        );
    }
    // 处理关联字段“店铺”
    if (
      !SheetUtils.isBlank(row.getShopInfoShopName()) &&
      SheetUtils.isBlank(row.getShopInfo())
    ) {
      ShopInfoSearchParamPo shopInfoSearchParam = new ShopInfoSearchParamPo();
      shopInfoSearchParam.setLimit(2); // 最大只返回二行记录
      shopInfoSearchParam.setShopNameEq(
        SheetUtils.trim(row.getShopInfoShopName())
      );
      shopInfoSearchParam.applySqlSegments();
      List<ShopInfoItemVo> shopInfoMatches = shopInfoMapper.search(
        shopInfoSearchParam
      );
      if (shopInfoMatches.size() == 0) {
        ir.addError("shopInfoShopName", "未能在店铺中找到匹配的数据");
      } else if (shopInfoMatches.size() > 1) {
        ir.addError(
          "shopInfoShopName",
          "关联不唯一，在店铺中找到多个匹配的数据"
        );
      } else {
        vo.setShopInfo(shopInfoMatches.get(0).getId());
      }
    }
    // 处理关联字段“站点”
    if (
      !SheetUtils.isBlank(row.getSiteName()) &&
      SheetUtils.isBlank(row.getSite())
    ) {
      SysRegionSearchParamPo siteSearchParam = new SysRegionSearchParamPo();
      siteSearchParam.setLimit(2); // 最大只返回二行记录
      siteSearchParam.setNameEq(SheetUtils.trim(row.getSiteName()));
      siteSearchParam.applySqlSegments();
      List<SysRegionItemVo> siteMatches = sysRegionMapper.search(
        siteSearchParam
      );
      if (siteMatches.size() == 0) {
        ir.addError("siteName", "未能在站点中找到匹配的数据");
      } else if (siteMatches.size() > 1) {
        ir.addError("siteName", "关联不唯一，在站点中找到多个匹配的数据");
      } else {
        vo.setSite(siteMatches.get(0).getId());
      }
    }
    // 处理关联字段“客选物流”
    if (
      !SheetUtils.isBlank(row.getDeliveryLogisticsLabel()) &&
      SheetUtils.isBlank(row.getDeliveryLogistics())
    ) {
      NavLogisticsProviderViewSearchParamPo deliveryLogisticsSearchParam =
        new NavLogisticsProviderViewSearchParamPo();
      deliveryLogisticsSearchParam.setLimit(2); // 最大只返回二行记录
      deliveryLogisticsSearchParam.setLabelEq(
        SheetUtils.trim(row.getDeliveryLogisticsLabel())
      );
      deliveryLogisticsSearchParam.applySqlSegments();
      List<NavLogisticsProviderViewItemVo> deliveryLogisticsMatches =
        navLogisticsProviderViewMapper.search(deliveryLogisticsSearchParam);
      if (deliveryLogisticsMatches.size() == 0) {
        ir.addError(
          "deliveryLogisticsLabel",
          "未能在物流管理-客选物流-视图中找到匹配的数据"
        );
      } else if (deliveryLogisticsMatches.size() > 1) {
        ir.addError(
          "deliveryLogisticsLabel",
          "关联不唯一，在物流管理-客选物流-视图中找到多个匹配的数据"
        );
      } else {
        vo.setDeliveryLogistics(deliveryLogisticsMatches.get(0).getId());
      }
    }
    // 处理关联字段“国家/地区”
    if (
      !SheetUtils.isBlank(row.getDeliveryCountryCountry()) &&
      SheetUtils.isBlank(row.getDeliveryCountry())
    ) {
      SysCountrySearchParamPo deliveryCountrySearchParam =
        new SysCountrySearchParamPo();
      deliveryCountrySearchParam.setLimit(2); // 最大只返回二行记录
      deliveryCountrySearchParam.setCountryEq(
        SheetUtils.trim(row.getDeliveryCountryCountry())
      );
      deliveryCountrySearchParam.applySqlSegments();
      List<SysCountryItemVo> deliveryCountryMatches = sysCountryMapper.search(
        deliveryCountrySearchParam
      );
      if (deliveryCountryMatches.size() == 0) {
        ir.addError("deliveryCountryCountry", "未能在国家中找到匹配的数据");
      } else if (deliveryCountryMatches.size() > 1) {
        ir.addError(
          "deliveryCountryCountry",
          "关联不唯一，在国家中找到多个匹配的数据"
        );
      } else {
        vo.setDeliveryCountry(deliveryCountryMatches.get(0).getId());
      }
    }
    // 处理关联字段“发货仓库”
    if (
      !SheetUtils.isBlank(row.getDeliveryWarehouseName()) &&
      SheetUtils.isBlank(row.getDeliveryWarehouse())
    ) {
      WarehouseSearchParamPo deliveryWarehouseSearchParam =
        new WarehouseSearchParamPo();
      deliveryWarehouseSearchParam.setLimit(2); // 最大只返回二行记录
      deliveryWarehouseSearchParam.setNameEq(
        SheetUtils.trim(row.getDeliveryWarehouseName())
      );
      deliveryWarehouseSearchParam.applySqlSegments();
      List<WarehouseItemVo> deliveryWarehouseMatches = warehouseMapper.search(
        deliveryWarehouseSearchParam
      );
      if (deliveryWarehouseMatches.size() == 0) {
        ir.addError(
          "deliveryWarehouseName",
          "未能在仓库即时库存中找到匹配的数据"
        );
      } else if (deliveryWarehouseMatches.size() > 1) {
        ir.addError(
          "deliveryWarehouseName",
          "关联不唯一，在仓库即时库存中找到多个匹配的数据"
        );
      } else {
        vo.setDeliveryWarehouse(deliveryWarehouseMatches.get(0).getId());
      }
    }
    // 处理关联字段“物流方式”
    if (
      !SheetUtils.isBlank(row.getDeliveryLogisticsChannelLabel()) &&
      SheetUtils.isBlank(row.getDeliveryLogisticsChannel())
    ) {
      NavLogisticsChannelViewSearchParamPo deliveryLogisticsChannelSearchParam =
        new NavLogisticsChannelViewSearchParamPo();
      deliveryLogisticsChannelSearchParam.setLimit(2); // 最大只返回二行记录
      deliveryLogisticsChannelSearchParam.setLabelEq(
        SheetUtils.trim(row.getDeliveryLogisticsChannelLabel())
      );
      deliveryLogisticsChannelSearchParam.applySqlSegments();
      List<NavLogisticsChannelViewItemVo> deliveryLogisticsChannelMatches =
        navLogisticsChannelViewMapper.search(
          deliveryLogisticsChannelSearchParam
        );
      if (deliveryLogisticsChannelMatches.size() == 0) {
        ir.addError(
          "deliveryLogisticsChannelLabel",
          "未能在物流管理-渠道基本信息-视图中找到匹配的数据"
        );
      } else if (deliveryLogisticsChannelMatches.size() > 1) {
        ir.addError(
          "deliveryLogisticsChannelLabel",
          "关联不唯一，在物流管理-渠道基本信息-视图中找到多个匹配的数据"
        );
      } else {
        vo.setDeliveryLogisticsChannel(
          deliveryLogisticsChannelMatches.get(0).getId()
        );
      }
    }

    return ir;
  }

  /**
   * 导入预览
   * @param sysFile 已上传到系统的文件
   * @param templateId 要使用的模版编号
   * @param allowOverrides 允许覆盖
   */
  @Override
  public List<ImportRow<NavSellOrderImportPo>> importPreview(
    SysFile sysFile,
    Long templateId,
    boolean allowOverrides
  ) throws Exception {
    SysImportTemplate importTemplate = null;
    if (templateId != null && templateId > 0) {
      importTemplate = importTemplateService.getById(templateId);
      if (importTemplate == null) {
        throw new RException("指定的模版不可用！");
      }
    }
    Map<String, Object> variables = new HashMap<>();

    // 标记由模版直接导入的字段集
    if (importTemplate != null) {
      variables.put(
        "IMPORT_FIELDS",
        importTemplate
          .getSetting()
          .getMappings()
          .stream()
          .map(SysImportTemplate.Mapping::getField)
          .collect(Collectors.toSet())
      );
    }
    try (InputStream in = fileService.read(sysFile)) {
      List<ImportRow<NavSellOrderImportPo>> rows = new ArrayList<>();

      // 读取 Excel 到 rows
      EasyExcel
        .read(in)
        .useDefaultListener(false)
        .registerReadListener(
          new TemplateModelBuildEventListener<>(
            NavSellOrderImportPo.class,
            importTemplate
          ) {
            @Override
            public void invokeRow(
              NavSellOrderImportPo row,
              AnalysisContext cxt
            ) {
              NavSellOrderVo vo = new NavSellOrderVo();
              ImportRow<NavSellOrderImportPo> ir = excelToImportRow(
                row,
                cxt.readRowHolder().getRowIndex(),
                vo,
                variables,
                allowOverrides
              );
              if (ir.isEmptyRow()) {
                return;
              }
              if (allowOverrides) {
                // FIXME: 未在平台上配置此对象《作为导入唯一识别》的《逻辑分组》配置，无法处理更新模式
              }
              rows.add(ir);
            }
          }
        )
        .sheet()
        .doRead();

      return rows;
    }
  }

  /**
   * 完成导入
   * @param rows 预导入的行信息
   */
  @DataActivity(action = SysDataActivityAction.Import)
  @Transactional(rollbackFor = Exception.class)
  @Override
  public void importDone(
    List<ImportRow<NavSellOrderImportPo>> rows,
    Long templateId
  ) throws Exception {
    SysImportTemplate importTemplate = null;
    if (templateId != null && templateId > 0) {
      importTemplate = importTemplateService.getById(templateId);
      if (importTemplate == null) {
        throw new RException("指定的模版不可用！");
      }
    }
    String sysImportBatchNo = StrUtil.concat(
      true,
      DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_MS_PATTERN),
      IdUtil.nanoId(4)
    );
    List<Long> importedIdList = new ArrayList<>();
    SysDataActivityAopHelper.clear();
    final SysDataActivityAopHelper.DataActivityAopContext context =
      SysDataActivityAopHelper.getOrCreateContext();
    Map<String, Object> variables = new HashMap<>();

    // 标记由模版直接导入的字段集
    if (importTemplate != null) {
      variables.put(
        "IMPORT_FIELDS",
        importTemplate
          .getSetting()
          .getMappings()
          .stream()
          .map(SysImportTemplate.Mapping::getField)
          .collect(Collectors.toSet())
      );
    }
    for (int i = 0; i < rows.size(); i++) {
      ImportRow<NavSellOrderImportPo> row = rows.get(i);
      Long updateId = row.getUpdateId();
      NavSellOrderVo vo = new NavSellOrderVo();
      row =
        excelToImportRow(row.getRow(), row.getRowNumber(), vo, variables, true);
      if (row.getErrors() != null && row.getErrors().size() > 0) {
        throw new RException(
          String.format(
            "第%d行（Excel第%d行）数据验证错误：%s",
            i + 1,
            row.getRowNumber(),
            row.getJoinErrorMessage()
          )
        );
      }
      if (updateId != null) {
        vo.setId(updateId);
      }
      // 重建"系统单号"
      if (
        importTemplate != null &&
        importTemplate
          .getSetting()
          .getMappings()
          .stream()
          .anyMatch(m ->
            Boolean.TRUE.equals(m.getNeedRecreate()) &&
            "orderId".equals(m.getField())
          )
      ) {
        vo.setOrderId(
          sysSerialService.getNewSerial(
            new NewSerialRequest(null, "NavSellOrder.orderId")
          )
        );
      }

      SheetUtils.setSysImportTemplateName(
        vo,
        null == importTemplate ? "默认模板" : importTemplate.getTitle()
      );
      SheetUtils.setSysImportBatchNo(vo, sysImportBatchNo);
      if (updateId == null) {
        importedIdList.add(create(vo));
      } else {
        self.update(vo);
        importedIdList.add(vo.getId());
      }
    }
    context.getIdList().addAll(importedIdList);
  }

  /**
   * 导出
   * @param templateId 使用模版（可以是 null 或 0 表示系统默认导出模版）
   * @param search 查询条件
   */
  @DataActivity(action = SysDataActivityAction.Export)
  @Override
  public void export(
    Long templateId,
    NavSellOrderSearchParamPo search,
    HttpServletResponse response
  ) throws Exception {
    if (templateId != null && templateId > 0) {
      SysImportTemplate sysImportTemplate = importTemplateService.getById(
        templateId
      );
      if (sysImportTemplate == null) {
        throw new RException("所选的导出模版不可用");
      }
      CustomExcelExport.CustomExcelExportOptions exportOptions =
        new CustomExcelExport.CustomExcelExportOptions();
      exportOptions.setImportTemplate(sysImportTemplate);
      exportOptions.setSearchParam(search);
      exportOptions.setMainService(this);
      exportOptions.addFieldMappingOption(
        "shopInfo",
        new CustomExcelExport.FieldMappingOption()
          .setConverter((o, r) ->
            String.valueOf(((NavSellOrderItemVo) r).getShopInfoShopName())
          )
      );
      exportOptions.addFieldMappingOption(
        "currency",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00015")
      );
      exportOptions.addFieldMappingOption(
        "type",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00122")
      );
      exportOptions.addFieldMappingOption(
        "status",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00143")
      );
      exportOptions.addFieldMappingOption(
        "site",
        new CustomExcelExport.FieldMappingOption()
          .setConverter((o, r) ->
            String.valueOf(((NavSellOrderItemVo) r).getSiteName())
          )
      );
      exportOptions.addFieldMappingOption(
        "tag",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00142")
      );
      exportOptions.addFieldMappingOption(
        "source",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00121")
      );
      exportOptions.addFieldMappingOption(
        "splitType",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00183")
      );
      exportOptions.addFieldMappingOption(
        "paymentWay",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00144")
      );
      exportOptions.addFieldMappingOption(
        "deliveryLogistics",
        new CustomExcelExport.FieldMappingOption()
          .setConverter((o, r) ->
            String.valueOf(((NavSellOrderItemVo) r).getDeliveryLogisticsLabel())
          )
      );
      exportOptions.addFieldMappingOption(
        "deliveryCountry",
        new CustomExcelExport.FieldMappingOption()
          .setConverter((o, r) ->
            String.valueOf(((NavSellOrderItemVo) r).getDeliveryCountryCountry())
          )
      );
      exportOptions.addFieldMappingOption(
        "deliveryAddressType",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00124")
      );
      exportOptions.addFieldMappingOption(
        "deliveryWidType",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00017")
      );
      exportOptions.addFieldMappingOption(
        "deliveryWarehouse",
        new CustomExcelExport.FieldMappingOption()
          .setConverter((o, r) ->
            String.valueOf(((NavSellOrderItemVo) r).getDeliveryWarehouseName())
          )
      );
      exportOptions.addFieldMappingOption(
        "deliveryLogisticsChannel",
        new CustomExcelExport.FieldMappingOption()
          .setConverter((o, r) ->
            String.valueOf(
              ((NavSellOrderItemVo) r).getDeliveryLogisticsChannelLabel()
            )
          )
      );
      exportOptions.addFieldMappingOption(
        "deliveryType",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00184")
      );
      exportOptions.addFieldMappingOption(
        "deliveryRecipientTaxType",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00141")
      );
      exportOptions.addFieldMappingOption(
        "deliverySenderTaxNoType",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00141")
      );
      exportOptions.addFieldMappingOption(
        "deliveryCodeOrder",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00008")
      );
      exportOptions.addFieldMappingOption(
        "deliveryThinkWeightUnit",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00113")
      );
      exportOptions.addFieldMappingOption(
        "deliveryThinkSizeUnit",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00146")
      );
      exportOptions.addFieldMappingOption(
        "deliveryThinkVolumeUnit",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00147")
      );
      exportOptions.addFieldMappingOption(
        "deliveryThinkFeeWeightUnit",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00113")
      );
      exportOptions.addFieldMappingOption(
        "deliveryRealWeightUnit",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00113")
      );
      exportOptions.addFieldMappingOption(
        "deliveryRealSizeUnit",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00146")
      );
      exportOptions.addFieldMappingOption(
        "deliveryRealVolumeUnit",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00147")
      );
      exportOptions.addFieldMappingOption(
        "deliveryRealFeeWeightUnit",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00113")
      );
      exportOptions.addFieldMappingOption(
        "deliveryRealCurrencyCode",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00015")
      );
      exportOptions.addFieldMappingOption(
        "deliveryStatus",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00028")
      );
      exportOptions.addFieldMappingOption(
        "cutStatus",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00178")
      );
      exportOptions.addFieldMappingOption(
        "distributionStatus",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00161")
      );
      exportOptions.addFieldMappingOption(
        "printFaceStatus",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00008")
      );
      exportOptions.addFieldMappingOption(
        "printOrderStatus",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00008")
      );
      exportOptions.addFieldMappingOption(
        "isTest",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00008")
      );
      exportOptions.addFieldMappingOption(
        "isWeigh",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00008")
      );
      exportOptions.addFieldMappingOption(
        "issuActRules",
        new CustomExcelExport.FieldMappingOption().setDictCode("SCM00133")
      );
      exportOptions.addStringFields(
        "orderId",
        "shopInfoShopName",
        "currency",
        "type",
        "status",
        "siteName",
        "tag",
        "source",
        "splitType",
        "remark",
        "paymentWay",
        "buyerName",
        "buyerEmail",
        "deliveryLogisticsLabel",
        "buyerLeaveWord",
        "deliveryReceipt",
        "deliveryZipCode",
        "deliveryPhone",
        "deliveryCountryCountry",
        "deliveryProvince",
        "deliveryCity",
        "deliveryArea",
        "deliveryHouseNumber",
        "deliveryCompany",
        "deliveryAddressType",
        "deliveryAddress1",
        "deliveryAddress2",
        "deliveryAddress3",
        "deliveryWidType",
        "deliveryWarehouseName",
        "deliveryLogisticsChannelLabel",
        "deliveryWaybillId",
        "deliveryTrackId",
        "deliveryPartnerOrderId",
        "deliveryIssuId",
        "deliveryType",
        "deliveryRecipientTaxType",
        "deliveryRecipientTaxNo",
        "deliveryRecipientIdentityNo",
        "deliverySenderTaxNoType",
        "deliverySenderTaxNo",
        "deliveryCodeOrder",
        "deliveryThinkWeightUnit",
        "deliveryThinkSizeUnit",
        "deliveryThinkVolumeUnit",
        "deliveryThinkFeeWeightUnit",
        "deliveryRealWeightUnit",
        "deliveryRealSizeUnit",
        "deliveryRealVolumeUnit",
        "deliveryRealFeeWeightUnit",
        "deliveryRealCurrencyCode",
        "deliveryStatus",
        "deliveryMessage",
        "deliveryRemark",
        "cutStatus",
        "distributionStatus",
        "printFaceStatus",
        "printOrderStatus",
        "isTest",
        "isWeigh",
        "woNumber",
        "boxId",
        "issuStatusExplain",
        "issuActRules"
      );

      String fileName = String.format(
        "订单管理(%s).xlsx",
        DateUtils.toString(null, DateUtils.PATTERN_DATE_TIME)
      );
      ResponseUtils.setAttachmentFileName(response, fileName);
      customExcelExport.run(exportOptions, response.getOutputStream());
      return;
    }
    List<SysDictAllItem> currencyItems = sysDictService.getDictItems(
      "SCM00015"
    );
    List<SysDictAllItem> typeItems = sysDictService.getDictItems("SCM00122");
    List<SysDictAllItem> statusItems = sysDictService.getDictItems("SCM00143");
    List<SysDictAllItem> tagItems = sysDictService.getDictItems("SCM00142");
    List<SysDictAllItem> sourceItems = sysDictService.getDictItems("SCM00121");
    List<SysDictAllItem> splitTypeItems = sysDictService.getDictItems(
      "SCM00183"
    );
    List<SysDictAllItem> paymentWayItems = sysDictService.getDictItems(
      "SCM00144"
    );
    List<SysDictAllItem> deliveryAddressTypeItems = sysDictService.getDictItems(
      "SCM00124"
    );
    List<SysDictAllItem> deliveryWidTypeItems = sysDictService.getDictItems(
      "SCM00017"
    );
    List<SysDictAllItem> deliveryTypeItems = sysDictService.getDictItems(
      "SCM00184"
    );
    List<SysDictAllItem> deliveryRecipientTaxTypeItems =
      sysDictService.getDictItems("SCM00141");
    List<SysDictAllItem> deliverySenderTaxNoTypeItems =
      sysDictService.getDictItems("SCM00141");
    List<SysDictAllItem> deliveryCodeOrderItems = sysDictService.getDictItems(
      "SCM00008"
    );
    List<SysDictAllItem> deliveryThinkWeightUnitItems =
      sysDictService.getDictItems("SCM00113");
    List<SysDictAllItem> deliveryThinkSizeUnitItems =
      sysDictService.getDictItems("SCM00146");
    List<SysDictAllItem> deliveryThinkVolumeUnitItems =
      sysDictService.getDictItems("SCM00147");
    List<SysDictAllItem> deliveryThinkFeeWeightUnitItems =
      sysDictService.getDictItems("SCM00113");
    List<SysDictAllItem> deliveryRealWeightUnitItems =
      sysDictService.getDictItems("SCM00113");
    List<SysDictAllItem> deliveryRealSizeUnitItems =
      sysDictService.getDictItems("SCM00146");
    List<SysDictAllItem> deliveryRealVolumeUnitItems =
      sysDictService.getDictItems("SCM00147");
    List<SysDictAllItem> deliveryRealFeeWeightUnitItems =
      sysDictService.getDictItems("SCM00113");
    List<SysDictAllItem> deliveryRealCurrencyCodeItems =
      sysDictService.getDictItems("SCM00015");
    List<SysDictAllItem> deliveryStatusItems = sysDictService.getDictItems(
      "SCM00028"
    );
    List<SysDictAllItem> cutStatusItems = sysDictService.getDictItems(
      "SCM00178"
    );
    List<SysDictAllItem> distributionStatusItems = sysDictService.getDictItems(
      "SCM00161"
    );
    List<SysDictAllItem> printFaceStatusItems = sysDictService.getDictItems(
      "SCM00008"
    );
    List<SysDictAllItem> printOrderStatusItems = sysDictService.getDictItems(
      "SCM00008"
    );
    List<SysDictAllItem> isTestItems = sysDictService.getDictItems("SCM00008");
    List<SysDictAllItem> isWeighItems = sysDictService.getDictItems("SCM00008");
    List<SysDictAllItem> issuActRulesItems = sysDictService.getDictItems(
      "SCM00133"
    );
    search.setPageSize(EXPORT_QUERY_MAX_SIZE);
    int current = 1;
    List<NavSellOrderExcelPo> items = new ArrayList<NavSellOrderExcelPo>();
    while (true) {
      search.setCurrent(current);
      search.setSelectFields(Collections.singletonList("@export"));
      Page<NavSellOrderItemVo> page = this.pageSearch(search);
      if (page.getTotal() > EXPORT_MAX_SIZE) {
        throw new RException("导出记录数超出限制！");
      }
      List<NavSellOrderItemVo> list = page.getRecords();
      if (list.isEmpty()) {
        break;
      }
      for (NavSellOrderItemVo item : list) {
        NavSellOrderExcelPo excel = new NavSellOrderExcelPo();
        BeanUtils.copyProperties(item, excel);
        if (item.getCurrency() != null) {
          currencyItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getCurrency()))
            .findFirst()
            .ifPresent(i -> excel.setCurrency(i.getItemText()));
        }
        if (item.getType() != null) {
          typeItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getType()))
            .findFirst()
            .ifPresent(i -> excel.setType(i.getItemText()));
        }
        if (item.getStatus() != null) {
          statusItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getStatus()))
            .findFirst()
            .ifPresent(i -> excel.setStatus(i.getItemText()));
        }
        if (item.getTag() != null) {
          final List<String> TagValues = Arrays
            .stream(item.getTag().split(","))
            .filter(StringUtils::hasText)
            .collect(Collectors.toList());
          excel.setTag(
            tagItems
              .stream()
              .filter(i -> TagValues.contains(i.getItemValue()))
              .map(SysDictAllItem::getItemText)
              .collect(Collectors.joining(","))
          );
        }
        if (item.getSource() != null) {
          sourceItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getSource()))
            .findFirst()
            .ifPresent(i -> excel.setSource(i.getItemText()));
        }
        if (item.getSplitType() != null) {
          splitTypeItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getSplitType()))
            .findFirst()
            .ifPresent(i -> excel.setSplitType(i.getItemText()));
        }
        if (item.getPaymentWay() != null) {
          paymentWayItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getPaymentWay()))
            .findFirst()
            .ifPresent(i -> excel.setPaymentWay(i.getItemText()));
        }
        if (item.getDeliveryAddressType() != null) {
          deliveryAddressTypeItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getDeliveryAddressType()))
            .findFirst()
            .ifPresent(i -> excel.setDeliveryAddressType(i.getItemText()));
        }
        if (item.getDeliveryWidType() != null) {
          deliveryWidTypeItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getDeliveryWidType()))
            .findFirst()
            .ifPresent(i -> excel.setDeliveryWidType(i.getItemText()));
        }
        if (item.getDeliveryType() != null) {
          deliveryTypeItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getDeliveryType()))
            .findFirst()
            .ifPresent(i -> excel.setDeliveryType(i.getItemText()));
        }
        if (item.getDeliveryRecipientTaxType() != null) {
          deliveryRecipientTaxTypeItems
            .stream()
            .filter(i ->
              i.getItemValue().equals(item.getDeliveryRecipientTaxType())
            )
            .findFirst()
            .ifPresent(i -> excel.setDeliveryRecipientTaxType(i.getItemText()));
        }
        if (item.getDeliverySenderTaxNoType() != null) {
          deliverySenderTaxNoTypeItems
            .stream()
            .filter(i ->
              i.getItemValue().equals(item.getDeliverySenderTaxNoType())
            )
            .findFirst()
            .ifPresent(i -> excel.setDeliverySenderTaxNoType(i.getItemText()));
        }
        if (item.getDeliveryCodeOrder() != null) {
          deliveryCodeOrderItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getDeliveryCodeOrder()))
            .findFirst()
            .ifPresent(i -> excel.setDeliveryCodeOrder(i.getItemText()));
        }
        if (item.getDeliveryThinkWeightUnit() != null) {
          deliveryThinkWeightUnitItems
            .stream()
            .filter(i ->
              i.getItemValue().equals(item.getDeliveryThinkWeightUnit())
            )
            .findFirst()
            .ifPresent(i -> excel.setDeliveryThinkWeightUnit(i.getItemText()));
        }
        if (item.getDeliveryThinkSizeUnit() != null) {
          deliveryThinkSizeUnitItems
            .stream()
            .filter(i ->
              i.getItemValue().equals(item.getDeliveryThinkSizeUnit())
            )
            .findFirst()
            .ifPresent(i -> excel.setDeliveryThinkSizeUnit(i.getItemText()));
        }
        if (item.getDeliveryThinkVolumeUnit() != null) {
          deliveryThinkVolumeUnitItems
            .stream()
            .filter(i ->
              i.getItemValue().equals(item.getDeliveryThinkVolumeUnit())
            )
            .findFirst()
            .ifPresent(i -> excel.setDeliveryThinkVolumeUnit(i.getItemText()));
        }
        if (item.getDeliveryThinkFeeWeightUnit() != null) {
          deliveryThinkFeeWeightUnitItems
            .stream()
            .filter(i ->
              i.getItemValue().equals(item.getDeliveryThinkFeeWeightUnit())
            )
            .findFirst()
            .ifPresent(i -> excel.setDeliveryThinkFeeWeightUnit(i.getItemText())
            );
        }
        if (item.getDeliveryRealWeightUnit() != null) {
          deliveryRealWeightUnitItems
            .stream()
            .filter(i ->
              i.getItemValue().equals(item.getDeliveryRealWeightUnit())
            )
            .findFirst()
            .ifPresent(i -> excel.setDeliveryRealWeightUnit(i.getItemText()));
        }
        if (item.getDeliveryRealSizeUnit() != null) {
          deliveryRealSizeUnitItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getDeliveryRealSizeUnit())
            )
            .findFirst()
            .ifPresent(i -> excel.setDeliveryRealSizeUnit(i.getItemText()));
        }
        if (item.getDeliveryRealVolumeUnit() != null) {
          deliveryRealVolumeUnitItems
            .stream()
            .filter(i ->
              i.getItemValue().equals(item.getDeliveryRealVolumeUnit())
            )
            .findFirst()
            .ifPresent(i -> excel.setDeliveryRealVolumeUnit(i.getItemText()));
        }
        if (item.getDeliveryRealFeeWeightUnit() != null) {
          deliveryRealFeeWeightUnitItems
            .stream()
            .filter(i ->
              i.getItemValue().equals(item.getDeliveryRealFeeWeightUnit())
            )
            .findFirst()
            .ifPresent(i -> excel.setDeliveryRealFeeWeightUnit(i.getItemText())
            );
        }
        if (item.getDeliveryRealCurrencyCode() != null) {
          deliveryRealCurrencyCodeItems
            .stream()
            .filter(i ->
              i.getItemValue().equals(item.getDeliveryRealCurrencyCode())
            )
            .findFirst()
            .ifPresent(i -> excel.setDeliveryRealCurrencyCode(i.getItemText()));
        }
        if (item.getDeliveryStatus() != null) {
          deliveryStatusItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getDeliveryStatus()))
            .findFirst()
            .ifPresent(i -> excel.setDeliveryStatus(i.getItemText()));
        }
        if (item.getCutStatus() != null) {
          cutStatusItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getCutStatus()))
            .findFirst()
            .ifPresent(i -> excel.setCutStatus(i.getItemText()));
        }
        if (item.getDistributionStatus() != null) {
          distributionStatusItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getDistributionStatus()))
            .findFirst()
            .ifPresent(i -> excel.setDistributionStatus(i.getItemText()));
        }
        if (item.getPrintFaceStatus() != null) {
          printFaceStatusItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getPrintFaceStatus()))
            .findFirst()
            .ifPresent(i -> excel.setPrintFaceStatus(i.getItemText()));
        }
        if (item.getPrintOrderStatus() != null) {
          printOrderStatusItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getPrintOrderStatus()))
            .findFirst()
            .ifPresent(i -> excel.setPrintOrderStatus(i.getItemText()));
        }
        if (item.getIsTest() != null) {
          isTestItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getIsTest()))
            .findFirst()
            .ifPresent(i -> excel.setIsTest(i.getItemText()));
        }
        if (item.getIsWeigh() != null) {
          isWeighItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getIsWeigh()))
            .findFirst()
            .ifPresent(i -> excel.setIsWeigh(i.getItemText()));
        }
        if (item.getIssuActRules() != null) {
          issuActRulesItems
            .stream()
            .filter(i -> i.getItemValue().equals(item.getIssuActRules()))
            .findFirst()
            .ifPresent(i -> excel.setIssuActRules(i.getItemText()));
        }

        items.add(excel);
      }
      if (list.size() < EXPORT_QUERY_MAX_SIZE) {
        break;
      }
      current++;
    }

    String fileName = String.format(
      "订单管理(%s).xlsx",
      DateUtils.toString(null, DateUtils.PATTERN_DATE_TIME)
    );
    ResponseUtils.setAttachmentFileName(response, fileName);
    EasyExcel
      .write(response.getOutputStream())
      .registerWriteHandler(new CustomExcelHandler())
      .sheet()
      .head(NavSellOrderExcelPo.class)
      .doWrite(items);
  }

  /**
   * 通过系统单号查询订单管理主键(重复时返回最新的主键)
   */
  @Override
  public Long getIdByOrderId(String orderId) {
    return this.baseMapper.getIdByOrderId(orderId);
  }

  /**
   * 通过系统单号查询订单管理多主键(重复时返回最新的主键)
   */
  @Override
  public List<Long> getIdsByOrderId(List<String> list) {
    return this.baseMapper.getIdsByOrderId(list);
  }

  /**
   * 通过订单管理主键查询系统单号
   */
  @Override
  public String getOrderIdById(Long id) {
    return this.baseMapper.getOrderIdById(id);
  }

  /**
   * 通过订单管理主键查询系统单号列表
   */
  @Override
  public List<String> getOrderIdByIds(List<Long> ids) {
    List<Map<String, Object>> maps = this.baseMapper.getOrderIdByIds(ids);
    // 将返回重新排列为输入相同顺序
    return ids
      .stream()
      .map(id -> {
        Optional<Map<String, Object>> optionalMap = maps
          .stream()
          .filter(map -> id.equals(map.get("id")))
          .findFirst();
        return optionalMap
          .map(stringObjectMap -> (String) stringObjectMap.get("orderId"))
          .orElse(null);
      })
      .collect(Collectors.toList());
  }

  /**
   * 获取详情
   * @param id 订单管理的主键
   */
  @DataActivity(action = SysDataActivityAction.View)
  @Override
  public NavSellOrderVo getVoById(Long id) throws Exception {
    NavSellOrderVo vo = this.baseMapper.selectVoById(id);
    if (vo == null) {
      return null;
    }

    NavSellOrderPlatformSearchParamPo platformSearchParamPo =
      new NavSellOrderPlatformSearchParamPo();
    platformSearchParamPo.setParentNavSellOrder(id);
    platformSearchParamPo.getExtendData().put("queryMode", "sub");
    platformSearchParamPo.getExtendData().put("queryParent", "NavSellOrder");
    platformSearchParamPo.applySqlSegments();
    vo.setPlatform(navSellOrderPlatformService.search(platformSearchParamPo));

    NavSellOrderTransactionSearchParamPo transactionSearchParamPo =
      new NavSellOrderTransactionSearchParamPo();
    transactionSearchParamPo.setParentNavSellOrder(id);
    transactionSearchParamPo.getExtendData().put("queryMode", "sub");
    transactionSearchParamPo.getExtendData().put("queryParent", "NavSellOrder");
    transactionSearchParamPo.applySqlSegments();
    vo.setTransaction(
      navSellOrderTransactionService.search(transactionSearchParamPo)
    );

    NavSellOrderDetailSearchParamPo productSearchParamPo =
      new NavSellOrderDetailSearchParamPo();
    productSearchParamPo.setParentNavSellOrder(id);
    productSearchParamPo.getExtendData().put("queryMode", "sub");
    productSearchParamPo.getExtendData().put("queryParent", "NavSellOrder");
    productSearchParamPo.applySqlSegments();
    vo.setProduct(navSellOrderDetailService.search(productSearchParamPo));

    NavSellOrderDeclareSearchParamPo declareSearchParamPo =
      new NavSellOrderDeclareSearchParamPo();
    declareSearchParamPo.setParentNavSellOrder(id);
    declareSearchParamPo.getExtendData().put("queryMode", "sub");
    declareSearchParamPo.getExtendData().put("queryParent", "NavSellOrder");
    declareSearchParamPo.applySqlSegments();
    vo.setDeclare(navSellOrderDeclareService.search(declareSearchParamPo));

    return vo;
  }

  /**
   * 主列表上要附加“平台信息”子表的部分字段
   * @param items 项目列表
   * @param sort 子表排序
   */
  protected void fillPartOfPlatform(
    List<NavSellOrderItemVo> items,
    String sort
  ) {
    NavSellOrderPlatformSearchParamPo platformSearchParamPo =
      new NavSellOrderPlatformSearchParamPo();
    platformSearchParamPo.setSort(sort);
    platformSearchParamPo.setSelectFields(
      List.of(
        "parentNavSellOrder",
        "purchaseTime",
        "paymentTime",
        "deliveryTime",
        "platformOrderId",
        "latestShipTime",
        "platform",
        "computedLatestShipTime"
      )
    );
    platformSearchParamPo.setParentNavSellOrderInList(
      items.stream().map(NavSellOrderItemVo::getId).collect(Collectors.toList())
    );
    navSellOrderPlatformService
      .search(platformSearchParamPo)
      .forEach(platform -> {
        NavSellOrderItemVo item = ListUtils.find(
          items,
          i -> Objects.equals(i.getId(), platform.getParentNavSellOrder())
        );
        if (item == null) return;
        if (item.getPlatformPurchaseTime() == null) {
          item.setPlatformPurchaseTime(new ArrayList<>());
        }
        item.getPlatformPurchaseTime().add(platform.getPurchaseTime());

        if (item.getPlatformPaymentTime() == null) {
          item.setPlatformPaymentTime(new ArrayList<>());
        }
        item.getPlatformPaymentTime().add(platform.getPaymentTime());

        if (item.getPlatformDeliveryTime() == null) {
          item.setPlatformDeliveryTime(new ArrayList<>());
        }
        item.getPlatformDeliveryTime().add(platform.getDeliveryTime());

        if (item.getPlatformPlatformOrderId() == null) {
          item.setPlatformPlatformOrderId(new ArrayList<>());
        }
        item.getPlatformPlatformOrderId().add(platform.getPlatformOrderId());

        if (item.getPlatformLatestShipTime() == null) {
          item.setPlatformLatestShipTime(new ArrayList<>());
        }
        item.getPlatformLatestShipTime().add(platform.getLatestShipTime());

        if (item.getPlatformPlatform() == null) {
          item.setPlatformPlatform(new ArrayList<>());
        }
        item.getPlatformPlatform().add(platform.getPlatform());
      });
  }

  /**
   * 主列表上要附加“交易信息”子表的部分字段
   * @param items 项目列表
   * @param sort 子表排序
   */
  protected void fillPartOfTransaction(
    List<NavSellOrderItemVo> items,
    String sort
  ) {
    NavSellOrderTransactionSearchParamPo transactionSearchParamPo =
      new NavSellOrderTransactionSearchParamPo();
    transactionSearchParamPo.setSort(sort);
    transactionSearchParamPo.setSelectFields(
      List.of("parentNavSellOrder", "amount", "totalAmount", "thinkGrossProfit")
    );
    transactionSearchParamPo.setParentNavSellOrderInList(
      items.stream().map(NavSellOrderItemVo::getId).collect(Collectors.toList())
    );
    navSellOrderTransactionService
      .search(transactionSearchParamPo)
      .forEach(transaction -> {
        NavSellOrderItemVo item = ListUtils.find(
          items,
          i -> Objects.equals(i.getId(), transaction.getParentNavSellOrder())
        );
        if (item == null) return;
        if (item.getTransactionAmount() == null) {
          item.setTransactionAmount(new ArrayList<>());
        }
        item.getTransactionAmount().add(transaction.getAmount());

        if (item.getTransactionTotalAmount() == null) {
          item.setTransactionTotalAmount(new ArrayList<>());
        }
        item.getTransactionTotalAmount().add(transaction.getTotalAmount());

        if (item.getTransactionThinkGrossProfit() == null) {
          item.setTransactionThinkGrossProfit(new ArrayList<>());
        }
        item
          .getTransactionThinkGrossProfit()
          .add(transaction.getThinkGrossProfit());
      });
  }

  /**
   * 主列表上要附加“产品信息”子表的部分字段
   * @param items 项目列表
   * @param sort 子表排序
   */
  protected void fillPartOfProduct(
    List<NavSellOrderItemVo> items,
    String sort
  ) {
    NavSellOrderDetailSearchParamPo productSearchParamPo =
      new NavSellOrderDetailSearchParamPo();
    productSearchParamPo.setSort(sort);
    productSearchParamPo.setSelectFields(
      List.of(
        "parentNavSellOrder",
        "img",
        "sku",
        "quantity",
        "availableQuantity",
        "thinkDeliveryCost",
        "attribute",
        "msku"
      )
    );
    productSearchParamPo.setParentNavSellOrderInList(
      items.stream().map(NavSellOrderItemVo::getId).collect(Collectors.toList())
    );
    navSellOrderDetailService
      .search(productSearchParamPo)
      .forEach(product -> {
        NavSellOrderItemVo item = ListUtils.find(
          items,
          i -> Objects.equals(i.getId(), product.getParentNavSellOrder())
        );
        if (item == null) return;
        if (item.getProductImg() == null) {
          item.setProductImg(new ArrayList<>());
        }
        item.getProductImg().add(product.getImg());

        if (item.getProductSku() == null) {
          item.setProductSku(new ArrayList<>());
        }
        item.getProductSku().add(product.getSku());

        if (item.getProductQuantity() == null) {
          item.setProductQuantity(new ArrayList<>());
        }
        item.getProductQuantity().add(product.getQuantity());

        if (item.getProductAvailableQuantity() == null) {
          item.setProductAvailableQuantity(new ArrayList<>());
        }
        item.getProductAvailableQuantity().add(product.getAvailableQuantity());

        if (item.getProductThinkDeliveryCost() == null) {
          item.setProductThinkDeliveryCost(new ArrayList<>());
        }
        item.getProductThinkDeliveryCost().add(product.getThinkDeliveryCost());

        if (item.getProductAttribute() == null) {
          item.setProductAttribute(new ArrayList<>());
        }
        item.getProductAttribute().add(product.getAttribute());

        if (item.getProductMsku() == null) {
          item.setProductMsku(new ArrayList<>());
        }
        item.getProductMsku().add(product.getMsku());
      });
  }

  /**
   * 主列表上要附加“报关信息”子表的部分字段
   * @param items 项目列表
   * @param sort 子表排序
   */
  protected void fillPartOfDeclare(
    List<NavSellOrderItemVo> items,
    String sort
  ) {
    NavSellOrderDeclareSearchParamPo declareSearchParamPo =
      new NavSellOrderDeclareSearchParamPo();
    declareSearchParamPo.setSort(sort);
    declareSearchParamPo.setSelectFields(
      List.of(
        "parentNavSellOrder",
        "sku",
        "chineseName",
        "englishName",
        "quantity"
      )
    );
    declareSearchParamPo.setParentNavSellOrderInList(
      items.stream().map(NavSellOrderItemVo::getId).collect(Collectors.toList())
    );
    navSellOrderDeclareService
      .search(declareSearchParamPo)
      .forEach(declare -> {
        NavSellOrderItemVo item = ListUtils.find(
          items,
          i -> Objects.equals(i.getId(), declare.getParentNavSellOrder())
        );
        if (item == null) return;
        if (item.getDeclareSku() == null) {
          item.setDeclareSku(new ArrayList<>());
        }
        item.getDeclareSku().add(declare.getSku());

        if (item.getDeclareChineseName() == null) {
          item.setDeclareChineseName(new ArrayList<>());
        }
        item.getDeclareChineseName().add(declare.getChineseName());

        if (item.getDeclareEnglishName() == null) {
          item.setDeclareEnglishName(new ArrayList<>());
        }
        item.getDeclareEnglishName().add(declare.getEnglishName());

        if (item.getDeclareQuantity() == null) {
          item.setDeclareQuantity(new ArrayList<>());
        }
        item.getDeclareQuantity().add(declare.getQuantity());
      });
  }

  /**
   * 分页查询订单管理
   * @param search 查询条件
   * @return 订单管理分页查询结果
   */
  @Override
  public Page<NavSellOrderItemVo> pageSearch(NavSellOrderSearchParamPo search) {
    Page<NavSellOrderItemVo> page = new Page<>();
    if (
      Objects.nonNull(search.getWfStatus()) &&
      StringUtils.hasText(search.getFormName())
    ) {
      List<WorkFlow> workFlowList = workFlowService.queryWfListByStatus(
        search.getWfStatus(),
        search.getFormName()
      );
      if (CollectionUtils.isEmpty(workFlowList)) {
        return page;
      }
      List<Long> ids = workFlowList
        .stream()
        .map(WorkFlow::getRecordId)
        .collect(Collectors.toList());
      if (CollectionUtils.isEmpty(ids)) {
        return page;
      }
      search.setSelectedIds(ids);
    }
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    page = this.baseMapper.pageSearch(search.toPage(), search);
    List<Long> recordIds = page
      .getRecords()
      .stream()
      .map(NavSellOrderItemVo::getId)
      .collect(Collectors.toList());
    if (CollectionUtils.isEmpty(recordIds)) {
      return page;
    }
    List<WorkFlow> workFlows = workFlowService.queryWfList(
      recordIds,
      Collections.singletonList(search.getFormName())
    );
    if (CollectionUtils.isEmpty(workFlows)) {
      return page;
    }
    Map<Long, Integer> flowMap = workFlows
      .stream()
      .collect(Collectors.toMap(WorkFlow::getRecordId, WorkFlow::getWfStatus));
    page
      .getRecords()
      .stream()
      .forEach(item -> {
        if (!flowMap.containsKey(item.getId())) {
          return;
        }
        item.setWfStatus(flowMap.get(item.getId()));
      });
    return page;
  }

  /**
   * 通用方法，为列表添加子表数据
   * @param pageResult 列表结果
   */
  protected Page<?> appendWithChild(Page<NavSellOrderItemVo> pageResult) {
    return appendWithChild(pageResult, null);
  }

  /**
   * 通用方法，为列表添加子表数据
   * @param pageResult 列表结果
   * @param sort 子表排序
   */
  protected Page<?> appendWithChild(
    Page<NavSellOrderItemVo> pageResult,
    String sort
  ) {
    if (
      pageResult == null ||
      pageResult.getRecords() == null ||
      pageResult.getRecords().isEmpty()
    ) {
      return pageResult;
    }
    Page<JSONObject> withChildPage = new Page<>(
      pageResult.getCurrent(),
      pageResult.getSize(),
      pageResult.getTotal()
    );
    withChildPage.setRecords(new ArrayList<>());

    NavSellOrderDetailSearchParamPo productSearchParamPo =
      new NavSellOrderDetailSearchParamPo();
    productSearchParamPo.setSort(sort);
    productSearchParamPo.setPageSize(5);
    productSearchParamPo.setParentNavSellOrderInList(
      pageResult
        .getRecords()
        .stream()
        .map(NavSellOrderItemVo::getId)
        .collect(Collectors.toList())
    );

    Map<String, Page<NavSellOrderDetailItemVoPages>> productMaps =
      navSellOrderDetailService.pagesByParentNavSellOrder(productSearchParamPo);

    for (NavSellOrderItemVo itemVo : pageResult.getRecords()) {
      JSONObject itemJson = (JSONObject) JSONObject.toJSON(itemVo);
      itemJson.put("product", productMaps.get(itemVo.getId().toString()));
      withChildPage.getRecords().add(itemJson);
    }
    return withChildPage;
  }

  /**
   * 获取包括子表的查询结果
   * @param search 查询条件
   * @return 订单管理分页查询结果
   */
  @Override
  public Page<?> pageWithChildSearch(NavSellOrderSearchParamPo search) {
    return appendWithChild(pageSearch(search), search.toChildSort("product"));
  }

  /**
   * 仅获取子表的查询结果
   * @param parentId 主表编号
   * @param search 查询条件(仅使用分页参数，不处理其它条件)
   * @return
   */
  @Override
  public Page<?> pageOnlyChildSearch(
    Long parentId,
    NavSellOrderSearchParamPo search
  ) {
    NavSellOrderSearchParamPo parentSearchParam =
      new NavSellOrderSearchParamPo();
    parentSearchParam.setIdEq(parentId);
    List<NavSellOrderItemVo> parentList = search(parentSearchParam);
    if (parentList.size() > 0) {
      NavSellOrderItemVo itemVo = parentList.get(0);

      NavSellOrderDetailSearchParamPo productSearchParamPo =
        new NavSellOrderDetailSearchParamPo();
      productSearchParamPo.setPageSize(search.getPageSize());
      productSearchParamPo.setCurrent(search.getCurrent());
      productSearchParamPo.setParentNavSellOrder(itemVo.getId());
      return navSellOrderDetailService.pageSearch(productSearchParamPo);
    } else {
      return null;
    }
  }

  /**
   * 订单管理快速查询选项(有缓存)
   * @param search 查询条件
   * @return 选项结果
   */
  @Override
  @Cacheable(
    value = CacheConfig.FAST,
    key = "'NavSellOrderOptions::' + @userInfo.userTypeAndId + '::' + #search.keyword"
  )
  public List<OptionItem<NavSellOrderItemVo>> searchOptions(
    NavSellOrderSearchParamPo search
  ) {
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    return this.baseMapper.searchOptions(search);
  }

  /**
   * 列表查询订单管理
   * @param search 查询条件
   * @return 订单管理列表查询结果
   */
  @Override
  public List<NavSellOrderItemVo> search(NavSellOrderSearchParamPo search) {
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    return this.baseMapper.search(search);
  }

  /**
   * 查询订单管理最后更新时间
   * @param search 查询条件
   * @return 订单管理最后更新时间
   */
  @Override
  public Date searchLastUpdateTime(NavSellOrderSearchParamPo search) {
    return this.baseMapper.searchLastUpdateTime(search);
  }

  /**
   * 审核
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了审核操作"
  )
  @Override
  public void process(List<Long> ids) throws Exception {
    if (navSellOrderProcessAction == null) {
      throw new Exception("此操作当前不可用");
    }
    navSellOrderProcessAction.run(ids);
  }

  /**
   * 发货
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了发货操作"
  )
  @Override
  public void deliver(List<Long> ids) throws Exception {
    if (navSellOrderDeliverAction == null) {
      throw new Exception("此操作当前不可用");
    }
    navSellOrderDeliverAction.run(ids);
  }

  /**
   * 截单
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了截单操作"
  )
  @Override
  public void cut(List<Long> ids) throws Exception {
    if (navSellOrderCutAction == null) {
      throw new Exception("此操作当前不可用");
    }
    navSellOrderCutAction.run(ids);
  }

  /**
   * 生成采购单
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了生成采购单操作"
  )
  @Override
  public void createPurchase(List<Long> ids) throws Exception {
    if (navSellOrderCreatePurchaseAction == null) {
      throw new Exception("此操作当前不可用");
    }
    navSellOrderCreatePurchaseAction.run(ids);
  }

  /**
   * 合并检查
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了合并检查操作"
  )
  @Override
  public void joinTask() throws Exception {
    if (navSellOrderJoinTaskAction == null) {
      throw new Exception("此操作当前不可用");
    }
    navSellOrderJoinTaskAction.run();
  }

  /**
   * 拆分检查
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了拆分检查操作"
  )
  @Override
  public void splitTask() throws Exception {
    if (navSellOrderSplitTaskAction == null) {
      throw new Exception("此操作当前不可用");
    }
    navSellOrderSplitTaskAction.run();
  }

  /**
   * 更新报关信息
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了更新报关信息操作"
  )
  @Override
  public void declareToProduct(Long id) throws Exception {
    if (navSellOrderDeclareToProductAction == null) {
      throw new Exception("此操作当前不可用");
    }
    navSellOrderDeclareToProductAction.run(id);
  }

  /**
   * 不发货
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了不发货操作"
  )
  @Override
  public void noDeliver(List<Long> ids) throws Exception {
    if (navSellOrderNoDeliverAction == null) {
      throw new Exception("此操作当前不可用");
    }
    navSellOrderNoDeliverAction.run(ids);
  }

  /**
   * 冻结
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了冻结操作"
  )
  @Override
  public void freeze(List<Long> ids) throws Exception {
    if (navSellOrderFreezeAction == null) {
      throw new Exception("此操作当前不可用");
    }
    navSellOrderFreezeAction.run(ids);
  }

  /**
   * 取消冻结
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了取消冻结操作"
  )
  @Override
  public void unFreeze(List<Long> ids) throws Exception {
    if (navSellOrderUnFreezeAction == null) {
      throw new Exception("此操作当前不可用");
    }
    navSellOrderUnFreezeAction.run(ids);
  }

  /**
   * 标记标签
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了标记标签操作"
  )
  @Override
  public void changeTag(List<Long> ids) throws Exception {
    if (navSellOrderChangeTagAction == null) {
      throw new Exception("此操作当前不可用");
    }
    navSellOrderChangeTagAction.run(ids);
  }

  /**
   * 合并
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了合并操作"
  )
  @Override
  public void join(List<Long> ids) throws Exception {
    if (navSellOrderJoinAction == null) {
      throw new Exception("此操作当前不可用");
    }
    navSellOrderJoinAction.run(ids);
  }

  /**
   * 留言已处理
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了留言已处理操作"
  )
  @Override
  public void leaveMessageProcessed(List<Long> ids) throws Exception {
    if (navSellOrderLeaveMessageProcessedAction == null) {
      throw new Exception("此操作当前不可用");
    }
    navSellOrderLeaveMessageProcessedAction.run(ids);
  }

  /**
   * 发货
   */
  @DataActivity(
    action = SysDataActivityAction.Other,
    message = "%s执行了发货操作"
  )
  @Override
  public void pickingDeliver(List<Long> ids) throws Exception {
    if (navSellOrderPickingDeliverAction == null) {
      throw new Exception("此操作当前不可用");
    }
    navSellOrderPickingDeliverAction.run(ids);
  }

  /**
   * 视图选项卡标题上显示计数
   */

  @Override
  public Map getTabHeaderShowTotal() {
    NavSellOrderSearchParamPo search = new NavSellOrderSearchParamPo();
    return MapUtil
      .builder()
      .put("AllOrder", this.baseMapper.allOrderCount(search))
      .put("PendingAuditOrder", this.baseMapper.pendingAuditOrderCount(search))
      .put(
        "PendingDeliverOrder",
        this.baseMapper.pendingDeliverOrderCount(search)
      )
      .put("DeliverOrder", this.baseMapper.deliverOrderCount(search))
      .put("NoDeliverOrder", this.baseMapper.noDeliverOrderCount(search))
      .put(
        "PlatformDeliverOrder",
        this.baseMapper.platformDeliverOrderCount(search)
      )
      .put("CanJoinOrder", this.baseMapper.canJoinOrderCount(search))
      .build();
  }

  /**
   * 全部
   */
  @Override
  public List<NavSellOrderItemVo> allOrder(NavSellOrderSearchParamPo search) {
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    return this.baseMapper.allOrder(search);
  }

  /**
   * 全部分页
   */
  @Override
  public Page<NavSellOrderItemVo> allOrderPage(
    NavSellOrderSearchParamPo search
  ) {
    Page<NavSellOrderItemVo> allOrderPage = new Page<>();
    if (
      Objects.nonNull(search.getWfStatus()) &&
      StringUtils.hasText(search.getFormName())
    ) {
      List<WorkFlow> workFlowList = workFlowService.queryWfListByStatus(
        search.getWfStatus(),
        search.getFormName()
      );
      if (CollectionUtils.isEmpty(workFlowList)) {
        return allOrderPage;
      }
      List<Long> ids = workFlowList
        .stream()
        .map(WorkFlow::getRecordId)
        .collect(Collectors.toList());
      if (CollectionUtils.isEmpty(ids)) {
        return allOrderPage;
      }
      search.setSelectedIds(ids);
    }
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    allOrderPage =
      this.baseMapper.allOrderPage(
          search.toPage(this.baseMapper.allOrderCount(search)),
          search
        );
    if (
      search.getFillParts() == null ||
      search.getFillParts().contains("platform")
    ) {
      fillPartOfPlatform(
        allOrderPage.getRecords(),
        search.toChildSort("platform")
      );
    }
    if (
      search.getFillParts() == null ||
      search.getFillParts().contains("transaction")
    ) {
      fillPartOfTransaction(
        allOrderPage.getRecords(),
        search.toChildSort("transaction")
      );
    }
    if (
      search.getFillParts() == null || search.getFillParts().contains("product")
    ) {
      fillPartOfProduct(
        allOrderPage.getRecords(),
        search.toChildSort("product")
      );
    }
    List<Long> recordIds = allOrderPage
      .getRecords()
      .stream()
      .map(NavSellOrderItemVo::getId)
      .collect(Collectors.toList());
    if (CollectionUtils.isEmpty(recordIds)) {
      return allOrderPage;
    }
    List<WorkFlow> workFlows = workFlowService.queryWfList(
      recordIds,
      Collections.singletonList(search.getFormName())
    );
    if (CollectionUtils.isEmpty(workFlows)) {
      return allOrderPage;
    }
    Map<Long, Integer> flowMap = workFlows
      .stream()
      .collect(Collectors.toMap(WorkFlow::getRecordId, WorkFlow::getWfStatus));
    allOrderPage
      .getRecords()
      .stream()
      .forEach(item -> {
        if (!flowMap.containsKey(item.getId())) {
          return;
        }
        item.setWfStatus(flowMap.get(item.getId()));
      });

    return allOrderPage;
  }

  /**
   * 获取包括子表的查询结果
   * @param search 查询条件
   * @return 订单管理分页查询结果
   */
  @Override
  public Page<?> allOrderPageWithChildSearch(NavSellOrderSearchParamPo search) {
    search.setFillParts(List.of("platform", "transaction"));
    return appendWithChild(allOrderPage(search), search.toChildSort("product"));
  }

  /**
   * 查询全部最后更新时间
   * @param search 查询条件
   * @return 全部最后更新时间
   */
  @Override
  public Date allOrderLastUpdateTime(NavSellOrderSearchParamPo search) {
    return this.baseMapper.allOrderLastUpdateTime(search);
  }

  /**
   * 待审核
   */
  @Override
  public List<NavSellOrderItemVo> pendingAuditOrder(
    NavSellOrderSearchParamPo search
  ) {
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    return this.baseMapper.pendingAuditOrder(search);
  }

  /**
   * 待审核分页
   */
  @Override
  public Page<NavSellOrderItemVo> pendingAuditOrderPage(
    NavSellOrderSearchParamPo search
  ) {
    Page<NavSellOrderItemVo> pendingAuditOrderPage = new Page<>();
    if (
      Objects.nonNull(search.getWfStatus()) &&
      StringUtils.hasText(search.getFormName())
    ) {
      List<WorkFlow> workFlowList = workFlowService.queryWfListByStatus(
        search.getWfStatus(),
        search.getFormName()
      );
      if (CollectionUtils.isEmpty(workFlowList)) {
        return pendingAuditOrderPage;
      }
      List<Long> ids = workFlowList
        .stream()
        .map(WorkFlow::getRecordId)
        .collect(Collectors.toList());
      if (CollectionUtils.isEmpty(ids)) {
        return pendingAuditOrderPage;
      }
      search.setSelectedIds(ids);
    }
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    pendingAuditOrderPage =
      this.baseMapper.pendingAuditOrderPage(
          search.toPage(this.baseMapper.pendingAuditOrderCount(search)),
          search
        );
    if (
      search.getFillParts() == null ||
      search.getFillParts().contains("platform")
    ) {
      fillPartOfPlatform(
        pendingAuditOrderPage.getRecords(),
        search.toChildSort("platform")
      );
    }
    if (
      search.getFillParts() == null ||
      search.getFillParts().contains("transaction")
    ) {
      fillPartOfTransaction(
        pendingAuditOrderPage.getRecords(),
        search.toChildSort("transaction")
      );
    }
    if (
      search.getFillParts() == null || search.getFillParts().contains("product")
    ) {
      fillPartOfProduct(
        pendingAuditOrderPage.getRecords(),
        search.toChildSort("product")
      );
    }
    List<Long> recordIds = pendingAuditOrderPage
      .getRecords()
      .stream()
      .map(NavSellOrderItemVo::getId)
      .collect(Collectors.toList());
    if (CollectionUtils.isEmpty(recordIds)) {
      return pendingAuditOrderPage;
    }
    List<WorkFlow> workFlows = workFlowService.queryWfList(
      recordIds,
      Collections.singletonList(search.getFormName())
    );
    if (CollectionUtils.isEmpty(workFlows)) {
      return pendingAuditOrderPage;
    }
    Map<Long, Integer> flowMap = workFlows
      .stream()
      .collect(Collectors.toMap(WorkFlow::getRecordId, WorkFlow::getWfStatus));
    pendingAuditOrderPage
      .getRecords()
      .stream()
      .forEach(item -> {
        if (!flowMap.containsKey(item.getId())) {
          return;
        }
        item.setWfStatus(flowMap.get(item.getId()));
      });

    return pendingAuditOrderPage;
  }

  /**
   * 获取包括子表的查询结果
   * @param search 查询条件
   * @return 订单管理分页查询结果
   */
  @Override
  public Page<?> pendingAuditOrderPageWithChildSearch(
    NavSellOrderSearchParamPo search
  ) {
    search.setFillParts(List.of("platform", "transaction"));
    return appendWithChild(
      pendingAuditOrderPage(search),
      search.toChildSort("product")
    );
  }

  /**
   * 查询待审核最后更新时间
   * @param search 查询条件
   * @return 待审核最后更新时间
   */
  @Override
  public Date pendingAuditOrderLastUpdateTime(
    NavSellOrderSearchParamPo search
  ) {
    return this.baseMapper.pendingAuditOrderLastUpdateTime(search);
  }

  /**
   * 待发货
   */
  @Override
  public List<NavSellOrderItemVo> pendingDeliverOrder(
    NavSellOrderSearchParamPo search
  ) {
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    return this.baseMapper.pendingDeliverOrder(search);
  }

  /**
   * 待发货分页
   */
  @Override
  public Page<NavSellOrderItemVo> pendingDeliverOrderPage(
    NavSellOrderSearchParamPo search
  ) {
    Page<NavSellOrderItemVo> pendingDeliverOrderPage = new Page<>();
    if (
      Objects.nonNull(search.getWfStatus()) &&
      StringUtils.hasText(search.getFormName())
    ) {
      List<WorkFlow> workFlowList = workFlowService.queryWfListByStatus(
        search.getWfStatus(),
        search.getFormName()
      );
      if (CollectionUtils.isEmpty(workFlowList)) {
        return pendingDeliverOrderPage;
      }
      List<Long> ids = workFlowList
        .stream()
        .map(WorkFlow::getRecordId)
        .collect(Collectors.toList());
      if (CollectionUtils.isEmpty(ids)) {
        return pendingDeliverOrderPage;
      }
      search.setSelectedIds(ids);
    }
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    pendingDeliverOrderPage =
      this.baseMapper.pendingDeliverOrderPage(
          search.toPage(this.baseMapper.pendingDeliverOrderCount(search)),
          search
        );
    if (
      search.getFillParts() == null ||
      search.getFillParts().contains("platform")
    ) {
      fillPartOfPlatform(
        pendingDeliverOrderPage.getRecords(),
        search.toChildSort("platform")
      );
    }
    if (
      search.getFillParts() == null ||
      search.getFillParts().contains("transaction")
    ) {
      fillPartOfTransaction(
        pendingDeliverOrderPage.getRecords(),
        search.toChildSort("transaction")
      );
    }
    if (
      search.getFillParts() == null || search.getFillParts().contains("product")
    ) {
      fillPartOfProduct(
        pendingDeliverOrderPage.getRecords(),
        search.toChildSort("product")
      );
    }
    List<Long> recordIds = pendingDeliverOrderPage
      .getRecords()
      .stream()
      .map(NavSellOrderItemVo::getId)
      .collect(Collectors.toList());
    if (CollectionUtils.isEmpty(recordIds)) {
      return pendingDeliverOrderPage;
    }
    List<WorkFlow> workFlows = workFlowService.queryWfList(
      recordIds,
      Collections.singletonList(search.getFormName())
    );
    if (CollectionUtils.isEmpty(workFlows)) {
      return pendingDeliverOrderPage;
    }
    Map<Long, Integer> flowMap = workFlows
      .stream()
      .collect(Collectors.toMap(WorkFlow::getRecordId, WorkFlow::getWfStatus));
    pendingDeliverOrderPage
      .getRecords()
      .stream()
      .forEach(item -> {
        if (!flowMap.containsKey(item.getId())) {
          return;
        }
        item.setWfStatus(flowMap.get(item.getId()));
      });

    return pendingDeliverOrderPage;
  }

  /**
   * 获取包括子表的查询结果
   * @param search 查询条件
   * @return 订单管理分页查询结果
   */
  @Override
  public Page<?> pendingDeliverOrderPageWithChildSearch(
    NavSellOrderSearchParamPo search
  ) {
    search.setFillParts(List.of("platform", "transaction"));
    return appendWithChild(
      pendingDeliverOrderPage(search),
      search.toChildSort("product")
    );
  }

  /**
   * 查询待发货最后更新时间
   * @param search 查询条件
   * @return 待发货最后更新时间
   */
  @Override
  public Date pendingDeliverOrderLastUpdateTime(
    NavSellOrderSearchParamPo search
  ) {
    return this.baseMapper.pendingDeliverOrderLastUpdateTime(search);
  }

  /**
   * 已发货
   */
  @Override
  public List<NavSellOrderItemVo> deliverOrder(
    NavSellOrderSearchParamPo search
  ) {
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    return this.baseMapper.deliverOrder(search);
  }

  /**
   * 已发货分页
   */
  @Override
  public Page<NavSellOrderItemVo> deliverOrderPage(
    NavSellOrderSearchParamPo search
  ) {
    Page<NavSellOrderItemVo> deliverOrderPage = new Page<>();
    if (
      Objects.nonNull(search.getWfStatus()) &&
      StringUtils.hasText(search.getFormName())
    ) {
      List<WorkFlow> workFlowList = workFlowService.queryWfListByStatus(
        search.getWfStatus(),
        search.getFormName()
      );
      if (CollectionUtils.isEmpty(workFlowList)) {
        return deliverOrderPage;
      }
      List<Long> ids = workFlowList
        .stream()
        .map(WorkFlow::getRecordId)
        .collect(Collectors.toList());
      if (CollectionUtils.isEmpty(ids)) {
        return deliverOrderPage;
      }
      search.setSelectedIds(ids);
    }
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    deliverOrderPage =
      this.baseMapper.deliverOrderPage(
          search.toPage(this.baseMapper.deliverOrderCount(search)),
          search
        );
    if (
      search.getFillParts() == null ||
      search.getFillParts().contains("platform")
    ) {
      fillPartOfPlatform(
        deliverOrderPage.getRecords(),
        search.toChildSort("platform")
      );
    }
    if (
      search.getFillParts() == null ||
      search.getFillParts().contains("transaction")
    ) {
      fillPartOfTransaction(
        deliverOrderPage.getRecords(),
        search.toChildSort("transaction")
      );
    }
    if (
      search.getFillParts() == null || search.getFillParts().contains("product")
    ) {
      fillPartOfProduct(
        deliverOrderPage.getRecords(),
        search.toChildSort("product")
      );
    }
    List<Long> recordIds = deliverOrderPage
      .getRecords()
      .stream()
      .map(NavSellOrderItemVo::getId)
      .collect(Collectors.toList());
    if (CollectionUtils.isEmpty(recordIds)) {
      return deliverOrderPage;
    }
    List<WorkFlow> workFlows = workFlowService.queryWfList(
      recordIds,
      Collections.singletonList(search.getFormName())
    );
    if (CollectionUtils.isEmpty(workFlows)) {
      return deliverOrderPage;
    }
    Map<Long, Integer> flowMap = workFlows
      .stream()
      .collect(Collectors.toMap(WorkFlow::getRecordId, WorkFlow::getWfStatus));
    deliverOrderPage
      .getRecords()
      .stream()
      .forEach(item -> {
        if (!flowMap.containsKey(item.getId())) {
          return;
        }
        item.setWfStatus(flowMap.get(item.getId()));
      });

    return deliverOrderPage;
  }

  /**
   * 获取包括子表的查询结果
   * @param search 查询条件
   * @return 订单管理分页查询结果
   */
  @Override
  public Page<?> deliverOrderPageWithChildSearch(
    NavSellOrderSearchParamPo search
  ) {
    search.setFillParts(List.of("platform", "transaction"));
    return appendWithChild(
      deliverOrderPage(search),
      search.toChildSort("product")
    );
  }

  /**
   * 查询已发货最后更新时间
   * @param search 查询条件
   * @return 已发货最后更新时间
   */
  @Override
  public Date deliverOrderLastUpdateTime(NavSellOrderSearchParamPo search) {
    return this.baseMapper.deliverOrderLastUpdateTime(search);
  }

  /**
   * 不发货
   */
  @Override
  public List<NavSellOrderItemVo> noDeliverOrder(
    NavSellOrderSearchParamPo search
  ) {
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    return this.baseMapper.noDeliverOrder(search);
  }

  /**
   * 不发货分页
   */
  @Override
  public Page<NavSellOrderItemVo> noDeliverOrderPage(
    NavSellOrderSearchParamPo search
  ) {
    Page<NavSellOrderItemVo> noDeliverOrderPage = new Page<>();
    if (
      Objects.nonNull(search.getWfStatus()) &&
      StringUtils.hasText(search.getFormName())
    ) {
      List<WorkFlow> workFlowList = workFlowService.queryWfListByStatus(
        search.getWfStatus(),
        search.getFormName()
      );
      if (CollectionUtils.isEmpty(workFlowList)) {
        return noDeliverOrderPage;
      }
      List<Long> ids = workFlowList
        .stream()
        .map(WorkFlow::getRecordId)
        .collect(Collectors.toList());
      if (CollectionUtils.isEmpty(ids)) {
        return noDeliverOrderPage;
      }
      search.setSelectedIds(ids);
    }
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    noDeliverOrderPage =
      this.baseMapper.noDeliverOrderPage(
          search.toPage(this.baseMapper.noDeliverOrderCount(search)),
          search
        );
    if (
      search.getFillParts() == null ||
      search.getFillParts().contains("platform")
    ) {
      fillPartOfPlatform(
        noDeliverOrderPage.getRecords(),
        search.toChildSort("platform")
      );
    }
    if (
      search.getFillParts() == null ||
      search.getFillParts().contains("transaction")
    ) {
      fillPartOfTransaction(
        noDeliverOrderPage.getRecords(),
        search.toChildSort("transaction")
      );
    }
    if (
      search.getFillParts() == null || search.getFillParts().contains("product")
    ) {
      fillPartOfProduct(
        noDeliverOrderPage.getRecords(),
        search.toChildSort("product")
      );
    }
    List<Long> recordIds = noDeliverOrderPage
      .getRecords()
      .stream()
      .map(NavSellOrderItemVo::getId)
      .collect(Collectors.toList());
    if (CollectionUtils.isEmpty(recordIds)) {
      return noDeliverOrderPage;
    }
    List<WorkFlow> workFlows = workFlowService.queryWfList(
      recordIds,
      Collections.singletonList(search.getFormName())
    );
    if (CollectionUtils.isEmpty(workFlows)) {
      return noDeliverOrderPage;
    }
    Map<Long, Integer> flowMap = workFlows
      .stream()
      .collect(Collectors.toMap(WorkFlow::getRecordId, WorkFlow::getWfStatus));
    noDeliverOrderPage
      .getRecords()
      .stream()
      .forEach(item -> {
        if (!flowMap.containsKey(item.getId())) {
          return;
        }
        item.setWfStatus(flowMap.get(item.getId()));
      });

    return noDeliverOrderPage;
  }

  /**
   * 获取包括子表的查询结果
   * @param search 查询条件
   * @return 订单管理分页查询结果
   */
  @Override
  public Page<?> noDeliverOrderPageWithChildSearch(
    NavSellOrderSearchParamPo search
  ) {
    search.setFillParts(List.of("platform", "transaction"));
    return appendWithChild(
      noDeliverOrderPage(search),
      search.toChildSort("product")
    );
  }

  /**
   * 查询不发货最后更新时间
   * @param search 查询条件
   * @return 不发货最后更新时间
   */
  @Override
  public Date noDeliverOrderLastUpdateTime(NavSellOrderSearchParamPo search) {
    return this.baseMapper.noDeliverOrderLastUpdateTime(search);
  }

  /**
   * 平台发货
   */
  @Override
  public List<NavSellOrderItemVo> platformDeliverOrder(
    NavSellOrderSearchParamPo search
  ) {
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    return this.baseMapper.platformDeliverOrder(search);
  }

  /**
   * 平台发货分页
   */
  @Override
  public Page<NavSellOrderItemVo> platformDeliverOrderPage(
    NavSellOrderSearchParamPo search
  ) {
    Page<NavSellOrderItemVo> platformDeliverOrderPage = new Page<>();
    if (
      Objects.nonNull(search.getWfStatus()) &&
      StringUtils.hasText(search.getFormName())
    ) {
      List<WorkFlow> workFlowList = workFlowService.queryWfListByStatus(
        search.getWfStatus(),
        search.getFormName()
      );
      if (CollectionUtils.isEmpty(workFlowList)) {
        return platformDeliverOrderPage;
      }
      List<Long> ids = workFlowList
        .stream()
        .map(WorkFlow::getRecordId)
        .collect(Collectors.toList());
      if (CollectionUtils.isEmpty(ids)) {
        return platformDeliverOrderPage;
      }
      search.setSelectedIds(ids);
    }
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    platformDeliverOrderPage =
      this.baseMapper.platformDeliverOrderPage(
          search.toPage(this.baseMapper.platformDeliverOrderCount(search)),
          search
        );
    if (
      search.getFillParts() == null ||
      search.getFillParts().contains("platform")
    ) {
      fillPartOfPlatform(
        platformDeliverOrderPage.getRecords(),
        search.toChildSort("platform")
      );
    }
    if (
      search.getFillParts() == null ||
      search.getFillParts().contains("transaction")
    ) {
      fillPartOfTransaction(
        platformDeliverOrderPage.getRecords(),
        search.toChildSort("transaction")
      );
    }
    if (
      search.getFillParts() == null || search.getFillParts().contains("product")
    ) {
      fillPartOfProduct(
        platformDeliverOrderPage.getRecords(),
        search.toChildSort("product")
      );
    }
    List<Long> recordIds = platformDeliverOrderPage
      .getRecords()
      .stream()
      .map(NavSellOrderItemVo::getId)
      .collect(Collectors.toList());
    if (CollectionUtils.isEmpty(recordIds)) {
      return platformDeliverOrderPage;
    }
    List<WorkFlow> workFlows = workFlowService.queryWfList(
      recordIds,
      Collections.singletonList(search.getFormName())
    );
    if (CollectionUtils.isEmpty(workFlows)) {
      return platformDeliverOrderPage;
    }
    Map<Long, Integer> flowMap = workFlows
      .stream()
      .collect(Collectors.toMap(WorkFlow::getRecordId, WorkFlow::getWfStatus));
    platformDeliverOrderPage
      .getRecords()
      .stream()
      .forEach(item -> {
        if (!flowMap.containsKey(item.getId())) {
          return;
        }
        item.setWfStatus(flowMap.get(item.getId()));
      });

    return platformDeliverOrderPage;
  }

  /**
   * 获取包括子表的查询结果
   * @param search 查询条件
   * @return 订单管理分页查询结果
   */
  @Override
  public Page<?> platformDeliverOrderPageWithChildSearch(
    NavSellOrderSearchParamPo search
  ) {
    search.setFillParts(List.of("platform", "transaction"));
    return appendWithChild(
      platformDeliverOrderPage(search),
      search.toChildSort("product")
    );
  }

  /**
   * 查询平台发货最后更新时间
   * @param search 查询条件
   * @return 平台发货最后更新时间
   */
  @Override
  public Date platformDeliverOrderLastUpdateTime(
    NavSellOrderSearchParamPo search
  ) {
    return this.baseMapper.platformDeliverOrderLastUpdateTime(search);
  }

  /**
   * 可合并订单
   */
  @Override
  public List<NavSellOrderItemVo> canJoinOrder(
    NavSellOrderSearchParamPo search
  ) {
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    return this.baseMapper.canJoinOrder(search);
  }

  /**
   * 可合并订单分页
   */
  @Override
  public Page<NavSellOrderItemVo> canJoinOrderPage(
    NavSellOrderSearchParamPo search
  ) {
    Page<NavSellOrderItemVo> canJoinOrderPage = new Page<>();
    if (
      Objects.nonNull(search.getWfStatus()) &&
      StringUtils.hasText(search.getFormName())
    ) {
      List<WorkFlow> workFlowList = workFlowService.queryWfListByStatus(
        search.getWfStatus(),
        search.getFormName()
      );
      if (CollectionUtils.isEmpty(workFlowList)) {
        return canJoinOrderPage;
      }
      List<Long> ids = workFlowList
        .stream()
        .map(WorkFlow::getRecordId)
        .collect(Collectors.toList());
      if (CollectionUtils.isEmpty(ids)) {
        return canJoinOrderPage;
      }
      search.setSelectedIds(ids);
    }
    search.initSort("t.id desc", "t.", SORT_FIELD_MAP);
    canJoinOrderPage =
      this.baseMapper.canJoinOrderPage(
          search.toPage(this.baseMapper.canJoinOrderCount(search)),
          search
        );
    if (
      search.getFillParts() == null ||
      search.getFillParts().contains("platform")
    ) {
      fillPartOfPlatform(
        canJoinOrderPage.getRecords(),
        search.toChildSort("platform")
      );
    }
    if (
      search.getFillParts() == null ||
      search.getFillParts().contains("transaction")
    ) {
      fillPartOfTransaction(
        canJoinOrderPage.getRecords(),
        search.toChildSort("transaction")
      );
    }
    if (
      search.getFillParts() == null || search.getFillParts().contains("product")
    ) {
      fillPartOfProduct(
        canJoinOrderPage.getRecords(),
        search.toChildSort("product")
      );
    }
    List<Long> recordIds = canJoinOrderPage
      .getRecords()
      .stream()
      .map(NavSellOrderItemVo::getId)
      .collect(Collectors.toList());
    if (CollectionUtils.isEmpty(recordIds)) {
      return canJoinOrderPage;
    }
    List<WorkFlow> workFlows = workFlowService.queryWfList(
      recordIds,
      Collections.singletonList(search.getFormName())
    );
    if (CollectionUtils.isEmpty(workFlows)) {
      return canJoinOrderPage;
    }
    Map<Long, Integer> flowMap = workFlows
      .stream()
      .collect(Collectors.toMap(WorkFlow::getRecordId, WorkFlow::getWfStatus));
    canJoinOrderPage
      .getRecords()
      .stream()
      .forEach(item -> {
        if (!flowMap.containsKey(item.getId())) {
          return;
        }
        item.setWfStatus(flowMap.get(item.getId()));
      });

    return canJoinOrderPage;
  }

  /**
   * 获取包括子表的查询结果
   * @param search 查询条件
   * @return 订单管理分页查询结果
   */
  @Override
  public Page<?> canJoinOrderPageWithChildSearch(
    NavSellOrderSearchParamPo search
  ) {
    search.setFillParts(List.of("platform", "transaction"));
    return appendWithChild(
      canJoinOrderPage(search),
      search.toChildSort("product")
    );
  }

  /**
   * 查询可合并订单最后更新时间
   * @param search 查询条件
   * @return 可合并订单最后更新时间
   */
  @Override
  public Date canJoinOrderLastUpdateTime(NavSellOrderSearchParamPo search) {
    return this.baseMapper.canJoinOrderLastUpdateTime(search);
  }

  /**
   * 查询合并订单
   */
  @Override
  public Page<NavSellOrderSelectJoinOrderResult> selectJoinOrder(
    PageSearch param
  ) {
    JwtUserInfo currentUser = JwtUserInfo.fromHeader();
    if (currentUser != null) {
      param.setCurrentUserId(currentUser.getUserId());
    }
    param.setDisableDataPremissions(true);
    return this.baseMapper.selectJoinOrder(param.toPage(), param);
  }

  /**
   * 查询拆分订单
   */
  @Override
  public Page<NavSellOrderSelectSplitOrderResult> selectSplitOrder(
    PageSearch param
  ) {
    JwtUserInfo currentUser = JwtUserInfo.fromHeader();
    if (currentUser != null) {
      param.setCurrentUserId(currentUser.getUserId());
    }
    param.setDisableDataPremissions(true);
    return this.baseMapper.selectSplitOrder(param.toPage(), param);
  }

  /**
   * 库存预览
   */
  @Override
  public Page<NavSellOrderGetInventoryResult> getInventory(
    NavSellOrderGetInventoryParam param
  ) {
    JwtUserInfo currentUser = JwtUserInfo.fromHeader();
    if (currentUser != null) {
      param.setCurrentUserId(currentUser.getUserId());
    }
    param.setDisableDataPremissions(true);
    return this.baseMapper.getInventory(param.toPage(), param);
  }

  /**
   * 获取打单,面单,发货单打印主表信息
   */
  @Override
  public List<NavSellOrderSelectPrintResult> selectPrint(
    NavSellOrderSelectPrintParam param
  ) {
    return this.baseMapper.selectPrint(param);
  }

  /**
   * 获取打单,面单,发货单打印详情信息
   */
  @Override
  public List<NavSellOrderSelectPrintDetailResult> selectPrintDetail(
    NavSellOrderSelectPrintDetailParam param
  ) {
    return this.baseMapper.selectPrintDetail(param);
  }

  /**
   * 获取标签数量
   */
  @Override
  public Page<NavSellOrderSelectTagCountResult> selectTagCount(
    PageSearch param
  ) {
    JwtUserInfo currentUser = JwtUserInfo.fromHeader();
    if (currentUser != null) {
      param.setCurrentUserId(currentUser.getUserId());
    }
    param.setDisableDataPremissions(true);
    return this.baseMapper.selectTagCount(param.toPage(), param);
  }

  /**
   * 换货
   */
  @Override
  public Page<NavSellOrderSelectPariListResult> selectPariList(
    NavSellOrderSelectPariListParam param
  ) {
    JwtUserInfo currentUser = JwtUserInfo.fromHeader();
    if (currentUser != null) {
      param.setCurrentUserId(currentUser.getUserId());
    }
    param.setDisableDataPremissions(true);
    return this.baseMapper.selectPariList(param.toPage(), param);
  }

  /**
   * 配对
   */
  @Override
  public Page<NavSellOrderSelectProductResult> selectProduct(
    NavSellOrderSelectProductParam param
  ) {
    JwtUserInfo currentUser = JwtUserInfo.fromHeader();
    if (currentUser != null) {
      param.setCurrentUserId(currentUser.getUserId());
    }
    param.setDisableDataPremissions(true);
    return this.baseMapper.selectProduct(param.toPage(), param);
  }

  /**
   * 根据msku查询未配对列表
   */
  @Override
  public List<NavSellOrderSelectNoPariOrderIdListResult> selectNoPariOrderIdList(
    NavSellOrderSelectNoPariOrderIdListParam param
  ) {
    return this.baseMapper.selectNoPariOrderIdList(param);
  }

  /**
   * 查询预估出库成本
   */
  @Override
  public List<NavSellOrderSelectCostPriceResult> selectCostPrice(
    NavSellOrderSelectCostPriceParam param
  ) {
    return this.baseMapper.selectCostPrice(param);
  }
}
